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

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

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

✓ Accepted answer

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)

1 comment

0

it does not work.... im getting no errors

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