#Module table

1 messages · Page 1 of 1 (latest)

still nimbus
#

Hi, when i update the table by the function AddDamage the table is update same if i put a print in the module but the function GetDamageList return an empty table whereas if i update damage by AddDamage the table is remembering the last update so i don't know why its not working :

local module = {}

local damagelist = {}


function module.AddDamage(player : Player, damage : NumberValue)
    if damagelist[player] then
        damagelist[player] += damage
    else
        damagelist[player] = damage
    end
    print(damagelist)
end

function module.RefreshDamage()
    table.clear(damagelist)
end

function module.GetDamageList()
    table.sort(damagelist)
    return damagelist
end

return module
spice laurel
#

table.sort only works on arrays not dictionaries

#

remove the table.sort and see what it gives you

still nimbus
spice laurel
#

Still prints an empty table?

still nimbus
#

no

spice laurel
#

What?

still nimbus
#

its return an empty table from GetDamageList

#

same without table.sort

#

damn now its returning :
["AddDamage"] = "function",
["GetDamageList"] = "function",
["RefreshDamage"] = "function"

#

im not calling module

spice laurel
#

You're probably using it wrong then

#

it prints fine

still nimbus
#

local damagelist = damageMod.GetDamageList()

spice laurel
#
local damage = require(game.ReplicatedStorage.Damage)

while task.wait(3) do
      damage.AddDamage(game.Players:FindFirstChildWhichIsA("Player"), math.random(1,20))
    print(damage.GetDamageList())
end
still nimbus
#

oh its because i call it by a localscript

spice laurel
#

Client Server boundary

still nimbus
#

so i can't use in localscript ? 😭

#

i hate remote event

#

TY for helping

spice laurel
#

Server can't see what client has