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

Neither of my leaderstat scripts worked, whats wrong?

I have two scripts, One the local script that is inside the TextLabel which has the purpose of changing the text label so It is equal to the players Balance which is on the leaderstats. The other script is the overall leaderstat which is supposed to increase by .50 every second. First time trying to work with leaderstats.

LeaderStat Script [] Meant to increase by .5 every second(which didn't work)

game.Players.PlayerAdded:connect(function(player)
 local folder = Instance.new("Folder",player)
 folder.Name= "leaderstats"
 local Balance = Instance.new("IntValue",folder)
 Balance.Name="Balance"
 Balance.Value = 0 

 while true do
  wait(1)
  Balance.Value = Balance.Value + .5
 end
end)

TextLabel Script [] Meant to change the gui so it is equal to the players leaderstat Balance(which also didn't work)

local gui = script.Parent

gui.Text = "Balance:"..game.Players.LocalPlayer.leaderstats.Balance.Value

Note The leaderstat script is in the Workspace and the TextLabel LocalScript is under the TextLabel which is under the Frame which is under the ScreenGui which is obviously under StarterGui.

2 answers

✓ Accepted answer

###It does not change because you only updated the text once. Use a changed event that will fire each time a property changes.

game:GetService("Players").PlayerAdded:Connect(function(player) -- Switch to :Connect, :connect is deprecated

    local folder = Instance.new("Folder") -- parent argument is deprecated
    folder.Name= "leaderstats"
    folder.Parent = player -- always assign parent last 

    local Balance = Instance.new("IntValue")
    Balance.Name= "Balance"
    Balance.Value = 0 
    Balance.Parent = folder

    while true do
        wait(1)
        Balance.Value = Balance.Value + 5 -- You made an IntValue, use NumberValue if you want .5

    end
end)

###Gui script:

local plr = game:GetService("Players").LocalPlayer
local ls = plr:WaitForChild("leaderstats")

ls.Balance.Changed:Connect(function(value)
    script.Parent.Text = "Balance: " .. value 
end)

2 comments

0

ok so the leaderstats script worked, I saw that it worked. But the gui script didnt ,_,

0

How do?

So if you want this work so use these scripts:

Leaderstats

function PlayerAdded(player)
	local folder = Instance.new("Folder",player)
 folder.Name= "leaderstats"
 local Balance = Instance.new("IntValue",folder)
 Balance.Name="Balance"
 Balance.Value = 0 
while true do
  wait(1)
  Balance.Value = Balance.Value + .5
end
end

game.Players.PlayerAdded:Connect(PlayerAdded)

TextLabel

local gui = script.Parent

while wait(0) do
gui.Text = "Balance:".. game.Players.LocalPlayer.leaderstats.Balance.Value
end

2 comments

0

That script is going to break lol

0

what script?

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