local Player = game.Players.LocalPlayer local Size = Player.leaderstats.Size script.Parent.MouseButton1Click:Connect(function() Size.Value = Size.Value + 1 end)
This is assuming you've created the leaderstats
in the player somewhere else in your game.
This error is likely occurring because this script is executing before the creation of the leaderstats
and its values within it. You need to utilize WaitForChild, which will yield your current thread until a child of the specified name is found in the Instance
you are checking.
local Player = game.Players.LocalPlayer local leaderstats = Player:WaitForChild("leaderstats") local Size = leaderstats:WaitForChild("Size")
You are essentially telling your script to wait until it finds leaderstats
in Player
and Size
in leaderstats
, and then execute the rest of your script.
Try Instance:WaitForChild(string name, double timeout)
local plr = game:GetService(“Players”).LocalPlayer local stats = plr:WaitForChild”leaderstats” local size = stats:WaitForChild”Size” script.Parent.MouseButton1Click:Connect(function() size.Value = size.Value + 1 end)