I have a variable in my server script that is for a part. I want to pass to my local script. how would I do that with a remote event?
✓ ANSWER ACCEPTED
how do I pass a variable from server to client with a remote event?
2 answers
✓ Accepted answer
I assume that you have a RemoteEvent in ReplicatedStorage. First, you have the fire the RemoteEvent with the player argument, it refers to the client you want to fire.
game.Players.PlayerAdded:Connect(function(plr)
game.ReplicatedStorage.RemoteEvent:FireClient(plr)
end)
Then, add arguments after plr to pass the arguments to your LocalScript.
game.Players.PlayerAdded:Connect(function(plr)
game.ReplicatedStorage.RemoteEvent:FireClient(plr, game.Workspace.Part)
end)
In the LocalScript, write this.
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(part)
--Write what you want to do on the client side.
end)
game.ReplicatedStorage.RemoteEvent:FireClient(player, part) --Add more commas and values to pass more things.
--Client
game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(part) --Just add it by the order
part.Transparency = 1 --For example
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Note: The shortcut keyword "workspace" is more reliable then game.Workspace:>