Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

why remotes's values are not being correctly grabbed?

So i have a local script that fires a remote, the remote is being fired, but the value with it is not correct, instead of printing the desired value on the local, it's printing the player's name, there are the scripts related to that function:

Server

remote = script.Parent.ValueStorage:WaitForChild("SwitchModes")

remote.OnServerEvent:Connect(function(currentmode)
	print(currentmode)
end)

Local (not full script)

currentmode = "Stun" -- all functions related to the value that's supposed to be sent to server.
script.Parent.ValueStorage.SwitchModes:FireServer(currentmode)

I suppose that the remote is printing the value that already comes with the remote, when its fired, the player, but its printing the name and not the player model, so i really don't know what exactly is going on. help would be appreciated...

1 answer

✓ Accepted answer

When Fireing from Client to Server the first argument will always be the player that fired it, then whatever you passed. so in the server script it should be

remote = script.Parent.ValueStorage:WaitForChild("SwitchModes")

remote.OnServerEvent:Connect(function(Player,currentmode)
    print(currentmode)
end)

6 comments

0

Thank you!

0

np

0

Hey, i have another problem, at first i thought it worked, but it seems like to be the same, what variable did you use for Player, i did game:GetService("Players").LocalPlayer, but it still prints the player name and not currentmode's value, currentmode value is definitively not the player name...

0

you wont need a variable to pass as the player, it will automatically find which players local script fired the server and define it for you

0

This video script guider made helped me out a ton: https://www.youtube.com/watch?v=4Dc_bri9mjs if you have further questions just feel free to ask

1

lol i found out that i inserted the variables wrong in function :v all working

This discussion is preserved as it was. New answers, comments, and votes are closed.