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

How would a textlabel show the Intvalue of leaderstats?

local Players = game:GetService("Players")
local LocalPlayers = Players.LocalPlayer.PlayerGui

Players.PlayerAdded:Connect(function(player)
	if player then
		local folder = Instance.new('Folder')
		folder.Name = 'leaderstats'
		folder.Parent = player
		
		local coins = Instance.new('IntValue')
		coins.Name = 'Coins'
		coins.Parent = folder
		coins.Value = 0
		
		local rank = Instance.new('StringValue')
		rank.Name = 'Rank'
		rank.Parent = folder
		rank.Value = player:GetRoleInGroup(950346) --Used Frappé as an example as I don't have a group yet.
	end
end)

local CoinAmount = LocalPlayers.LeaderStats.TextLabel

Players.PlayerAdded:Connect(function(player)
	while true do
		CoinAmount.Text = tostring(Players.leaderstats.Coins.Value)
		
		wait(0.5)
	end
end)

Error I'm getting: ServerScriptService.LeaderBoard:2: attempt to index nil with 'PlayerGui' - Server - LeaderBoard:2

What is wrong with the script?

1 answer

Easy

Requirements: Make a textlabel and add in a local script

Local script:

while wait() do
	local player = game.Players.LocalPlayer
	script.Parent.Text = ""..player:WaitForChild("leaderstats"):FindFirstChild("Coins").Value
end

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