This may be a simple question but i need help finding a way to receive variables from a client script to a server script.
Try this
for _, v in pairs(game:GetService("Players"):GetPlayers()) do -- we use a for loop to get every player in the server
--Code
end
This my not work can i ask what the scripts do
Try this Instead
You need to put a RemoteEvent in ReplicatedStroage
Then this will fire a remote event in ReplicatedStorage (server script)
game.ReplicatedStroage.RemoteEvent:FireAllClients()
Then in the other script put (local script)
game.ReplicatedStroage.RemoteEvent:OnClientEvent()
1 Like
To receive variables from a client script to a server script, use remote events:
I suggest you learn how to use a remote event. That’s literally what you are describing.
i started dong that, i’ll continue
I would suggest using RemoteEvents for this.
You can create a RemoteEvent in the ReplicatedStorage, and use this code.
--on the client (LocalScript)
local variable = 1 --set this to whatever you want
game.ReplicatedStorage:WaitForChild('RemoteEvent'):FireServer(variable)
--on the server (Script)
game.ReplicatedStorage:WaitForChild('RemoteEvent').OnServerEvent:Connect(function(player, variable)
print(variable)
--player is the player who sent the variable
--variable is the variable you sent
end)
If you get stuck, here is some more information about RemoteEvents.