for i = 1,90 do
wait(1)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local remoteEvent = ReplicatedStorage:WaitForChild("SetTimer")
for d = 1,#players do
remoteEvent:FireClient(players[d])
end
And I want to change a player’s gui, how can I send a value from the server script to the local script?
Loop through the players and fire the remote event for each of them. Then on the client side in a local script when onclientevent then change the player’s GUI stuff
I feel like I missed something it is hard to type on mobile
With FireAllClients, you do the OnClientEvent in a local script, so you can just define player as game.Players.LocalPlayer, and then change whatever part of the GUI you want.
If you just want to affect the local player, only do FireClient
So would this be correct? I’m trying to use my current integer variable in the for loop for the countdown text timer.
Server script:
for i = 1,90 do
wait(1)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local remoteEvent = ReplicatedStorage:WaitForChild("SetTimer")
local timer = i
remoteEvent:FireAllClients(timer)
and my localscript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("SetTimer")
function changeTimerText(timer)
game.Players.LocalPlayer.PlayerGui.Countdown.ImageLabel.Timer.Text = tonumber(timer)
end
remoteEvent.OnClientEvent:Connect()
All you do is just step on the part and the timer starts. I went into test mode so that I could have 2 players, and both of them saw the timer going up