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.
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.