So i made a leaderstats script and a gui that shows your leaderstats value, but for some reason it dosent update and i dont know why, here is the leaderstats script
game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local money = Instance.new("IntValue") money.Name = "Cash" money.Parent = leaderstats money.Value = 0 local crops = Instance.new("IntValue") crops.Name = "Crops" crops.Parent = leaderstats crops.Value = 100 local level = Instance.new("IntValue") level.Name = "Level" level.Parent = leaderstats level.Value = 0 end)
and here is my gui script
local player = game:GetService("Players").LocalPlayer local cash = player.leaderstats.Cash.Value script.Parent.Text = math.floor(cash) cash.Changed:Connect(function() script.Parent.Text = math.floor(cash) end)
You put a .Value
after getting the cash inside leaderstats.
Text requires a string, not a number.
Remove the .Value
after defining the player's cash as Changed
is an event of an instance, not a number (IntValue's value).
Use the tostring()
function that converts a number into a string.
Use WaitForChild()
to make sure the leaderstats and cash have been created by the other script.
Remove math.floor()
as you do not need to use them since IntValue's automatically round numbers to the nearest whole number.
local player = game:GetService("Players").LocalPlayer local cash = player:WaitForChild("leaderstats"):WaitForChild("Cash") script.Parent.Text = tostring(cash.Value) cash.Changed:Connect(function() script.Parent.Text = tostring(cash.Value) end)