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

Leaderstats is not a valid member of Player?

Asked by 6 years ago

The error in the question, is what repeatedly shows up in this script that is supposed to make a player's speed equal to their leaderstats value.

local player = game:GetService("Players").LocalPlayer
local char = player.Character

player.leaderstats.Speed.Changed:connect(function()
    char.Humanoid.WalkSpeed = player.leaderstats.Speed.Value + 16
end)
0
Have you tried print debugging? frostysubatomiczero 51 — 6y
0
Maybe try adding a wait() to the beginning? Without more details on how leaderstats is being created, I can't help you much. whenallthepigsfly 541 — 6y
0
player:WaitForChild("leaderstats"):WaitForChild("Speed").Changed:Connect(function() (make sure that the Speed IntValue is actually in leaderstats, not in the player) iddash 45 — 6y
0
I already told him that haha. @iddash. But he's using a serverscript so he shouldn't use localplayer. awfulszn 394 — 6y
View all comments (2 more)
0
o kl mb iddash 45 — 6y
0
ok so what these comments are telling me is i should try using waitforchild on all of them, make sure int value is in leaderstats, and this is meant to be a serverscript taunter165 30 — 6y

1 answer

Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
6 years ago

leaderstats is not yet a member of the player when you are setting an event listener. Add a WaitForChild() to only continue once the value actually exists.

Ad

Answer this question