Player problem in serverscript

I wanted to make a timer for my game, but also want to change the UI timer. It worked, but I noticed it was only for the player joined and I deleted the function and left the following code:

local timer = game.Workspace.Colors.Timer 
timer.Value = 10
if plr:WaitForChild("PlayerGui"):WaitForChild("Timer"):WaitForChild("Time") then
	plr:WaitForChild("PlayerGui"):WaitForChild("Timer"):WaitForChild("Time").Text = 10
	while timer.Value > 0 do
		wait(1)
		timer.Value = timer.Value - 1
		plr:WaitForChild("PlayerGui"):WaitForChild("Timer"):WaitForChild("Time").Text = tostring(timer.Value)
	end
end

I tried to think but I can’t think of anything that solves it,

1 Like

Is this the full code? I assume not cause the plr variable is not defined in the code.

Anyhow what you would want to do is this:

local function TimerForPlayer(plr, Time)
	local timer = game.Workspace.Colors.Timer 
	timer.Value = Time or 10
	if plr:WaitForChild("PlayerGui"):WaitForChild("Timer"):WaitForChild("Time") then
		plr:WaitForChild("PlayerGui"):WaitForChild("Timer"):WaitForChild("Time").Text = 10
		while timer.Value > 0 do
			wait(1)
			timer.Value = timer.Value - 1
			plr:WaitForChild("PlayerGui"):WaitForChild("Timer"):WaitForChild("Time").Text = tostring(timer.Value)
		end
	end
end


game.Players.PlayerAdded:Connect(function(plr)
	TimerForPlayer(plr)
end)

Anytime a player joins it will display the timer for them.
Now in the case you want to do it for all players at once, you can do this:

local function TimerForPlayer(plr, Time)
	local timer = game.Workspace.Colors.Timer 
	timer.Value = Time or 10
	if plr:WaitForChild("PlayerGui"):WaitForChild("Timer"):WaitForChild("Time") then
		plr:WaitForChild("PlayerGui"):WaitForChild("Timer"):WaitForChild("Time").Text = 10
		while timer.Value > 0 do
			wait(1)
			timer.Value = timer.Value - 1
			plr:WaitForChild("PlayerGui"):WaitForChild("Timer"):WaitForChild("Time").Text = tostring(timer.Value)
		end
	end
end


for _, Player in game.Players:GetPlayers() do
	TimerForPlayer(Player)
end

yup :]
1 Like

this is a server script? you cant edit player gui in server scripts bub
convert to local script use remote events to tell client when to display the timer

1 Like

Actually you can in fact edit UI that is in a players PlayerGui.

2 Likes

I tried doing the “for all player” because I’m trying to make four corners.
Nothing happens on the script.

local function TimerForPlayer(plr, Time)
	local timer = game.Workspace.Colors.Timer
	if Time == nil then
		Time = 10
	end
	timer.Value = Time or 10
	if plr:WaitForChild("PlayerGui"):WaitForChild("Timer"):WaitForChild("Time") then
		plr:WaitForChild("PlayerGui"):WaitForChild("Timer"):WaitForChild("Time").Text = 10
		while timer.Value > 0 do
			wait(1)
			timer.Value -= 1
			plr:WaitForChild("PlayerGui"):WaitForChild("Timer"):WaitForChild("Time").Text = tostring(timer.Value)
		end
	end
end


for _, Player in game.Players:GetPlayers() do
	TimerForPlayer(Player)
end

I’ll try the other one now

local timerUI = plr:WaitForChild(“PlayerGui”):WaitForChild(“Timer”):WaitForChild(“Time”)
Now you can state timerUI.Text = and not have to repeat that line over and over.

That’s all I’m going to say … you may want to look at a few tutorials on timers.