Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Neither of my leaderstat scripts worked, whats wrong?

Asked by
Burobuu 18
6 years ago

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

Log in to vote
0
Answered by 6 years ago

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)
0
ok so the leaderstats script worked, I saw that it worked. But the gui script didnt ,_, Burobuu 18 — 6y
0
How do? User#19524 175 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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
0
That script is going to break lol User#19524 175 — 6y
0
what script? DontGetTired255 6 — 6y

Answer this question