Ok so please don’t make fun of what I can do, I started a couple weeks ago. I was trying to make a script to give a player “Bucks”. That works, but I tried making a gui that shows the amount of money someone has, but that’s now working.
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Bucks = Instance.new("IntValue")
Bucks.Name = "Bucks"
Bucks.Parent = leaderstats
local Time = Instance.new("IntValue")
Time.Name = "Time"
Time.Parent = leaderstats
while wait(5) do
Bucks.Value = Bucks.Value + 5
end
local BucksDisplay = game.StarterGui.ScreenGui.TextButton.TextLabel
BucksDisplay.Text = Bucks.Value
end)
First off the while loop is looping and will never reach to what is below it. So you would either need to change the Gui text with a .Changed event or directly in the loop. Second, you must change the text on the client preferably and reference the Gui from the player’s PlayerGui.
Here’s a good version of it
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Bucks = Instance.new("IntValue")
Bucks.Name = "Bucks"
Bucks.Parent = leaderstats
local Time = Instance.new("IntValue")
Time.Name = "Time"
Time.Parent = leaderstats
coroutine.wrap(function() -- Creating the thread with this function
while true do
wait(5) -- prefer calling wait(5) here then in the condition of the loop
Bucks.Value = Bucks.Value + 5
end
end)() -- calling the thread
Bucks.Changed:Connect(function() -- Detecting everytime it changes
local BucksDisplay = player.PlayerGui.ScreenGui.TextButton.TextLabel
BucksDisplay.Text = Bucks.Value
end)
end)