I'm trying to pass a set of values from the server to the client when they request it. The four values are charge, maxcharge, downtime, and drain. They are all NumberValues located within a folder under a tool. the localscript is from that tool. Sometimes, this works correctly and there are no problems. However, there are other times where the values are nil. It seems all values are nil, though the error is thrown at charge specifically being nil.
I thought it might be that the NumberValues don't exist yet for the player which might cause replication errors, so there are wait()s above to yield until these exist. However, this was not helpful. I don't understand why this seems to work at random.
--local side
local function statrequest()
local charge, maxcharge, downtime, drain = game.ReplicatedStorage.StatRequest:InvokeServer()
return charge, maxcharge, downtime, drain
end
--server side
local function statrequest(player)
local Character = player:FindFirstChild("Character")
if Character then
local tooltag = Character:FindFirstChild("EquipmentToolTag", true)
if tooltag then
local equipstats = tooltag.Parent.equipStats
print(equipstats.Charge.Value, equipstats.MaxCharge.Value, equipstats.FireRate.Value, equipstats.Drain.Value)
return equipstats.Charge.Value, equipstats.MaxCharge.Value, equipstats.FireRate.Value, equipstats.Drain.Value
end
end
end
game.ReplicatedStorage.StatRequest.OnServerInvoke = statrequest

2 comments
thank you for the effort, but it still errors with waitforchild(). i think its definitely a networking issue though
Can I check the error in the output?