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

how do I pass a variable from server to client with a remote event?

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?

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)

1 comment

0

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

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.