Remove event question

If I have this code in my server script.

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?

1 Like

You can use parameters in the :FireClient(player, parameter1, parameter2)
https://developer.roblox.com/en-us/api-reference/function/RemoteEvent/FireClient

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 :thinking:

Can’t you just FireAllClients if you want all players to receive it?

2 Likes

Oh yeah forgot about that but if I am in a mini game I want it only to happen to certain players

First off, RemoteEvents have a FireAllClients() function, that fires for every client in the game, no need to loop through players and fire for them.

Anyways, to pass along information, just put the stuff you want to pass along as arguments when firing.

local var = 2

remote:FireAllClients(var)

The passed information will be received as parameters for remote.OnServerEvent and remote.OnClientEvent.

How do I get reference for the local player?
Like if I wanted to change all players GUI, is it possible to just affect the local player?

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()

Yep, that looks great.

30 chars

1 Like

I just tested with 2 clients in game, and the gui text doesn’t seem to change. Any idea why?
It says it’s looping, but the gui doesn’t change.

That is very strange. I decided to try and reproduce this in studio, and here is the file if you want to check it out.

FireAllClients_Repro.rbxl (23.4 KB)

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

thanks ill check it out
30ddsds