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

How do you send data over remote events?

Asked by 5 years ago

I have tried to send a value for another value in replicatedstorage using remote events but it doesn't seem to accept it, I have read the roblox help page and tried everything there but got no where, any suggestions or even samples of code to help?

1 answer

Log in to vote
0
Answered by 5 years ago

I don't know if you're talking about the Value object like IntValues, NumberValues, etc.. or some actual value. However they're both pretty much the same.

For sending data from Server to Client you need to specify which client you want to receive the data, the first value is always a player instance, and the rest is your choice. The same goes for Client to Server, but you don't need to put a player inside :FireServer() because Roblox automatically does it, it becomes the first argument in OnServerEvent.

Here is some sample code:

SERVER:

local event = game.ReplicatedStorage.SendData


event.OnServerEvent:Connect(function(player) -- player is always the first parameter
    print(player.Name)
end

CLIENT:

local event = game.ReplicatedStorage.SendData
local player = game.Players.LocalPlayer

while wait() do
    event:FireServer() -- dont have to define a player inside here, roblox already does it for u
end
Ad

Answer this question