I have a remote event being called.
game.ReplicatedStorage.PersonaRemoteEvents:FindFirstChild(persona):FindFirstChild(action):FireServer(icon)
I later connect several remote events (you can see with the variables that I’m trying to do this abstractly to make it as automated as I can) with a for loop:
for i, move in pairs(moveList) do
move.OnServerEvent:Connect(function(plr, icon)
-- Check if the cooldown is up for the move and make sure the player isn't dead
if cooldowns.Check(plr, move.Name) and plr.Character.Humanoid.Health > 0 then
print(icon) -- TODO: why is this nil? I'm passing it in??
-- Call the move and tick the cooldown
cooldowns.Down(plr, "notPersonaActive")
cooldowns.Start(plr, move.Name, cdList[move.Name].length, icon) -- Start cooldown first because the task.spawn() lets it run while the yielding move function runs
moveFunctions[move.Name](plr) -- No task.spawn() so that active is set properly as it has to wait for the move to finish
cooldowns.Up(plr, "notPersonaActive")
end
end)
end
For some reason, even though I am passing the icon through the remote event, when it gets to the print() statement for testing, I just get nil.
Some important things to note:
- Everything else works. The remote events, the connections, the calling, they all work. It’s this one thing that is weird.
- I tried adding another random parameter and printing it, just a string “e”. This works fine.
- When I print the full name of the object right before calling the remote event, it prints the full name perfectly fine.
- The “icon” being passed in is a locally created GUI object, a frame to be specific.
Why isn’t it working? How do I fix it?
EDIT: It seems the problem may be that passing the locally created object as a parameter gives it by reference, meaning the server still can’t access it. Having identified this problem, I’m still not sure of an efficient way to fix it, so if anyone knows, please share.