How to give leaderstat when after timer

I have made a timer and when it hits 0 i want it to give the player coins, i know how to give stats after a certain amount of time but only when its in the same script as the leaderstat it’s a separate script.

text = game.StarterGui.ScreenGui.Frame.TextLabel
while true do
	text.Text = 10
	wait(1)
	text.Text = 9
	wait(1)
	text.Text = 8
	wait(1)
	text.Text = 7
	wait(1)
	text.Text = 6
	wait(1)
	text.Text = 5
	wait(1)
	text.Text = 4
	wait(1)
	text.Text = 3
	wait(1)
	text.Text = 2
	wait(1)
	text.Text = 1
	wait(1)
	text.Text = 0
	game.StarterGui.ScreenGui.Frame.TextLabel.TextColor3 =Color3.fromRGB(70, 255, 49)
	game.StarterGui.money.moneyframe.moneytext.Transparency = 0
	Here is where cash should. be given
	wait(3)
	game.StarterGui.money.moneyframe.moneytext.Transparency = 1
	game.StarterGui.ScreenGui.Frame.TextLabel.TextColor3 =Color3.fromRGB(0, 0, 0)
end

You could make a global variable for the timer, and with that, you can access to that ‘timer’ from any script. [Dont forget to update the timer, in one script is enough, but make sure the sever can see it]

[There are more ways to do it]

i mean the timer restarts every time its over, but i want it to give cash when it hits 0 so you get cash every 10 seconds, how do i reference it?

Pleas show us your script, so we can see it visually

I would use ’ GetPropertyChangedSignal’ if it where me trying to access stats from another script so it can get the newest value.

1 Like

coins.Value = coins.Value + 1
doesn’t work so i dont know what would

First, instead of all those ‘wait’, you could simple do this

text = game.StarterGui.ScreenGui.Frame.TextLabel
while true do
	for i = 10,0,-1 do
        text.Text = i
        task.wait(1)
    end
end

1 Like

i knew there was a simpler way from something i made before but i forgot :sweat_smile:
thank you :slight_smile:

Now, about the cash :

local Player = game.Players.LocalPlayer
local Gui = Player:WaitForChild("PlayerGui"):WaitForChild("YourGuiNameHere")

if Player and Gui then
  if text.Text == 0 then
     Player:WaitForChild("leaderstats").Coins.Value += 1
  end
  Gui.Frame.TextLabel.TextColor3 = Color3.fromRGB(70, 255, 49)
  Gui.Frame.TextLabel.Visible = false
  task.Wait(3)
  Gui.Frame.TextLabel.Visible = true
 --rest of the code
end

1 Like

Notes :

1-You better use Remotes to communicate between client and server.
2-Use task.wait() and not wait()

local plr = game.Players.LocalPlayer
text = plr.PlayerGui.ScreenGui.Frame.TextLabel
while true do
	for i=10,0,-1 do
		text.Text = i
		wait(1)
	end
	plr.PlayerGui.ScreenGui.Frame.TextLabel.TextColor3 =Color3.fromRGB(70, 255, 49)
	plr.PlayerGui.money.moneyframe.moneytext.Transparency = 0
	plr.leaderstats.Cash.Value += 100 -- change cash with ur value and 100 with ur number
	wait(3)
	plr.PlayerGui.money.moneyframe.moneytext.Transparency = 1
	plr.PlayerGui.ScreenGui.Frame.TextLabel.TextColor3 =Color3.fromRGB(0, 0, 0)
end

place this in a localscript in startergui

1 Like

Don’t use wait, use task.wait()

i legit dont care about both i just use what i think is quick and that is wait so please dont correct me thanks

No need to be rude lol, She was simply telling you to not use wait() as it’s a older system, the task.wait has alot of new library’s / task implementation’s added to it,

[P.S] might wanna do some research their bud. :slight_smile:

listen bud i do know it and
[P.S] no research needed

i dont get it why people just straight up say use wait instead of task.wait do they think i dont know?

Apparently you don’t “Bud” not if you are still using “wait()” Might wanna do your research looks like you don’t even know the difference I think you need to look into it some more :slight_smile:

[P.S] Here is a link to give you some information you need: task

Don’t forget about sanity checks on remote events to ensure its nice and secure.

I agree, I gave him that code because it’s his code, I would do those checks ofc