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

why doesn't my leaderstats script work?i want to connect it to a text label

Asked by
seikkatsu 110
4 years ago
game:GetService("Players").PlayerAdded:Connect(function(p)
    -------------------< folder >------------------
    local leaderstats = Instance.new("Folder")
    leaderstats.Parent = p
    leaderstats.Name = "leaderstats"
    -------------------< strenght >-----------------------
    local str = Instance.new("IntValue")
    str.Parent = leaderstats
    str.Name = "Strenght"
    str.Value = 0
    ---------< strenght tied to the text label >---------
    local textLabel = game.StarterGui.Strenght.TextLabel
    textLabel.Text = "Strenght:"..str.Value
end)

i am trying to connect the int value that stores the strenght to a text label the int value works and adds 5 to its value every time i click any help?

1 answer

Log in to vote
3
Answered by
0_2k 496 Moderation Voter
4 years ago

Firstly, it'd work if you did it this way

game:GetService("Players").PlayerAdded:Connect(function(p)
    -------------------< folder >------------------
    local leaderstats = Instance.new("Folder")
    leaderstats.Parent = p
    leaderstats.Name = "leaderstats"
    -------------------< strenght >-----------------------
    local str = Instance.new("IntValue")
    str.Parent = leaderstats
    str.Name = "Strenght"
    str.Value = 0
    ---------< strenght tied to the text label >---------
    local textLabel = p.PlayerGuiGui.Strenght.TextLabel
    textLabel.Text = "Strenght:"..str.Value
end)

As a BETTER alternative is doing it this way.. GUI > Local Script

local stats = game.Players.LocalPlayer:WaitForChild("leaderstats")
local Strenght = stats.Strenght

Strenght.Changed:Connect(function()
    script.Parent.Strenght.TextLabel.Text = "Strenght: "..stats.Value
end)
0
it does not work.... im getting no errors seikkatsu 110 — 4y
Ad

Answer this question