Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Trying to make timer, but doesn't update text, and no errors in the output, how can I fix this?

I'm trying to make a timer, when a player buys something, but it doesn't work and it gives no errors.

There are two scripts one local, other is server.

Here is my local script (where a remote function gets fired):

-- Varabiles
local plr = game.Players.LocalPlayer

local replicatedStorage = game:GetService('ReplicatedStorage')
local remoteFunction = replicatedStorage:WaitForChild('PotionRemotes'):WaitForChild('DoubleClicks'):WaitForChild('TimerRemote')


game.Players.PlayerAdded:Connect(function(plr)
	-- keeps firing the remote function.
	while plr.Name do
		wait(1)
		remoteFunction:InvokeServer(plr)
	end
end)

Here is the server script:

-- replicated storage varaibes
local replicatedStorage = game:GetService('ReplicatedStorage')
local remoteFunction = replicatedStorage:WaitForChild('PotionRemotes'):WaitForChild('DoubleClicks'):WaitForChild('TimerRemote')



remoteFunction.OnServerInvoke = function(plr)
	-- time varabiles
	local timeLeft = game.ServerStorage.DataFolder:WaitForChild(plr.Name):WaitForChild('PotionsFolder'):WaitForChild('DoubleClicksTimeLeft')
	local isActive = game.ServerStorage.DataFolder:WaitForChild(plr.Name).PotionsFolder:WaitForChild("DoubleClicksActive").Value
	local timeLabel = plr.PlayerGui.DisplayGUI.DoubleClicksTimerFrame.TimeLabel
	local timerFrame = plr.PlayerGui.DisplayGUI.DoubleClicksTimerFrame
	-- checks if a bool value is true
	if isActive.Value == true then
		-- sets some guis active, and visible
		timerFrame.Active = true
		timeLabel.Active = true
		timerFrame.Visible = true
		
		-- checks if there is anymore time left
		if timeLeft.Value >= 1 then
			-- decreases
			timeLeft.Value = timeLeft.Value - 1
			-- updates text
			timeLabel.Text = timeLeft.Value..' sec left'
		else
			-- if not it'll set is active to false, and the frame invisible.
			isActive.Value = false
			timerFrame.Visible = false
		end
	end
end

Also the timer decreasing and updating text has to be in a server script so I can access the int values, and bool valaues.

1 comment

0

Why are you using a RemoteFunction when you don't return any value(s)?

2 answers

All UI changes (with the exception of BillboardGuis and SurfaceGuis) must be made on the client. After deciding what to put on the UI you should send a remote event from the server to the client to update that UI. If you want the change to be made for all player's UI, just use :FireAllClients().

I don't think changing gui on a server script would be very good. I think you can use FireAllClients() instead.

1 comment

0

I need an example of the FireClient way, since I'm not too sure how to do it.

This discussion is preserved as it was. New answers, comments, and votes are closed.