Why doesn't this work?

Hello!
I have made a timer here and I wanted to make the GUI be visible = false when the timer finishes. The timer has two scripts. One is a LocalScript, stored in StarterGUI > ScreenGUI > Frame > TextLabel. Script two is in ServerScriptService.

ServerScript:

local TimeAmount = 120

local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Timer = Instance.new("NumberValue")
Timer.Name = "Timer"
Timer.Parent = ReplicatedStorage
Timer.Value = TimeAmount

local TimerInfo = TweenInfo.new(
	TimeAmount,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.InOut
)

local TimerTween = TweenService:Create(Timer, TimerInfo, {Value = 0})

TimerTween:Play()

TimerTween.Completed:Connect(function()
	game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = false
end)

LocalScript:

local TimerValue = game:GetService("ReplicatedStorage"):WaitForChild("Timer")

local function FormatTime(seconds)
	return string.format("%d:%.02d.%.03d", seconds/60, seconds%60, seconds*1000%1000)
end

script.Parent.Text = FormatTime(TimerValue.Value)

TimerValue.Changed:Connect(function()
	script.Parent.Text = FormatTime(TimerValue.Value)
end)

I think the problem is in the ServerScript in ServerScriptService but im not sure. I would be verry thankfull if anybody could help me out.

Questions you might ask:

Q: Does the timer even work?
A: Yes, the timer works but it doesn’t make the GUI visible when the time is finished.

Q: Did you make this timer by yourself?
A: Kinda. I found a tutorial on YT but I scripted it myself so there could be some errors.

Q: Have you revised both scripts?
A: Yes, I have.

1 Like

You can’t directly change the visibility of the player gui from the server. you have to use remote events, or, as the timer value is in replicatedstorage, change the visibility from the local script

1 Like

Local player doesn’t exist on the server.

You can directly change the GUI from the server. The reason it’s not working is that he’s attempting to access “LocalPlayer” in his server script resulting in an error.

It is still bad practice.. They should use a remote event anyway, which will still likely fix their issue (RemoteEvent:FireAllClients()

Oh! I forgot I was trying to make the UI invisible for EVERYONE in the server. Then I need to do change

game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = false

for

game.StarterGui.ScreenGui.Frame.Visible = false

?

What do you mean? I have to use remote events? Is there any workaround?

There is no downside to using remote events. Why do you not wish to use them?

I have no idea how to make a remote event to make a UI invisible.

If you do that then only players who just join or recently respawned (assuming you have the reset UI setting on for the screen UI) will see the changes.

Poppy does raise a good point that it’s better practice to handle any sort of “effects” on the client so you don’t use much of the servers resources. BUT! If you still want to do it via server script just loop through all the players and update their UI (+ the starterui for those who join late):

TimerTween.Completed:Connect(function()
	for _, Player in ipairs(game:GetService("Players"):GetPlayers()) do
             Player.PlayerGui.ScreenGui.Frame.Visible = false -- update for each player currently in the server
end
game.StarterGui.ScreenGui.Frame.Visible -- update for players who join late

end)

Note there is typos because I’m on mobile!

1 Like

Thanks! I will explain what the timer if for anyway so you know what it is exactly what I want to achieve.
So, it is a wall climbing game, and while there is a round happening, the timer is saying how much time until round is finished. When the timer is done, the GUI becomes invisible. Then they vote for the wall. So the timer should be showing the same time for everyone. So if a player joins when it says 00:14:734 for another player, the new player sees the same time as all other players.