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

Why does it say leaderstats isn't a Valid Member of Player? Im Tyring to add Value to my leaderstat.

Asked by 5 years ago
local Player = game.Players.LocalPlayer 
local Size = Player.leaderstats.Size 

script.Parent.MouseButton1Click:Connect(function()
    Size.Value = Size.Value + 1
end)

3 answers

Log in to vote
1
Answered by
nilVector 812 Moderation Voter
5 years ago

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.

Ad
Log in to vote
0
Answered by 5 years ago

Fixed it with a simple data handler!

Log in to vote
0
Answered by 5 years ago

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)

Answer this question