Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
2
Answered by 4 years ago
Edited 4 years ago

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)
0
Note: The shortcut keyword "workspace" is more reliable then game.Workspace:> Ziffixture 6913 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
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)

Answer this question