So im making a game like work at a pizza place, the mainline of it is that you choose your job and then you work. the more things you get done the more money you get. When the serverTime is at a certain amount your paycheck shows up.
My problem:
I cant figure out the script for my ServerTime to go up... I made an intvalue in repstorage so yea.
I tried putting a script in server script storage but this does not work, the script was
local ServerTime = game.ReplicatedStorage.IntValue While 100 == 100 do wait(1) ServerTime.Value = ServerTime.Value + 1
this should make it give me 1 servertime each second, Right?
my next script was my gui script, i put it inside the button (claimButton) this was it
local frame = game.StarterGui.MyScreenGui.Frame local ServerTime = game.ReplicatedStorage.IntValue local AmountForClaim = game.ReplicatedStorage.AmountPerClaim local player = game.Players.LocalPlayer local mouse = player:GetMouse local Cash = player.leaderstats.Cash while 100 == 100 do if ServerTime.Value == 10 then if frame.Visible == false then frame.Visible = true ServerTime.Value = 0 script.Parent.MouseButton1Click:Connect(function() player.Cash.Value = player.Cash.Value + AmountForClaim if frame.Visible == true then wait() frame.Visible = false
But it does not work ;( what can I do to fix this?
While I do know how to make your script work, this code is highly inefficient, so let's replace it with something else. Go ahead and add a RemoteEvent inside ReplicatedStorage, and let's call it, say GivePaychecks.
In ServerScriptService, go ahead and add a script and add the following lines of code:
--Script to fire the RemoteEvent every 100 seconds --First, get ReplicatedStorage local ReplicatedStorage = game:GetService("ReplicatedStorage") --Get the remote event local givePaychecks = ReplicatedStorage:WaitForChild("GivePaychecks") --Seconds until the paychecks are given local waitTime = 100 while true do --Wait until the time specified wait(waitTime) --Now fire the remote event to all clients givePaychecks:FireAllClients() end
Make sure that you don't just copy and paste this script in, make sure you understand what every line is doing. I left comments in to help you. Now, replace the code in your GUI script with this:
--Get ReplicatedStorage local ReplicatedStorage = game:GetService("ReplicatedStorage") --Get remote event local givePaychecks = ReplicatedStorage:WaitForChild("GivePaychecks") --Get the frame local paycheckFrame = game.StarterGui.MyScreenGui.Frame --When the remote event is fired, execute the following code givePaychecks.OnClientEvent:Connect(function() --If they are not collecting their other paycheck, then: if not paycheckFrame.Visible then print("Not receiving paycheck, giving paycheck now...") paycheckFrame.Visible = true else print("Currently receiving other paycheck") end end)
Hope this helped!