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

I don't understand why this doesn't work, can someone tell me why it isnt working?

Asked by 10 years ago
game.Players.PlayerAdded:connect(function(plr)
    plr.CanLoadCharacterAppearance=false
    plr.Character.Humanoid.WalkSpeed=(0)
    wait(25)
    plr.Character.Humanoid.WalkSpeed=(40)
end)

Output:

Workspace.Script:3: attempt to index field 'Character' (a nil value)

1
try adding a :WaitForChild("Character") after the plr on lines 3+5 FearMeIAmLag 1161 — 10y

1 answer

Log in to vote
6
Answered by 10 years ago

Sorry if this doesn't help.

wait(0)
game.Players.PlayerAdded:connect(function(plr)
plr.CanLoadCharacterAppearance=false
repeat wait(0)until plr.Character --I usually use that because it will repeat wait(0) until the player's Character has loaded or exists finally, until then the script probly wont go on
if plr.Character:FindFirstChild("Humanoid")then --If script finds Humanoid within Character
plr.Character.Humanoid.WalkSpeed=(0)
wait(25)
plr.Character.Humanoid.WalkSpeed=(40)
end)
0
I had to edit it a bit, but it worked! Tempestatem 884 — 10y
0
No problem man, I'm glad I could help. ;) TheeDeathCaster 2368 — 10y
0
I added a wait(0) at the top as you can see, waits 0 seconds before loads, I do that for some of my scripts because there is a coding glitch out there where it wont work without a wait(0)at the top, I also used the 'repeat' to repeat waiting until the player's Character exists, and last but not least the 'if' statement is there to check if Humanoid exists. TheeDeathCaster 2368 — 10y
0
By the way. Instead of repeat wait()until plr.Character use prl.CharacterAdded:wait() Destrings 406 — 10y
0
Ugh, the cringe of my past is real. >.< TheeDeathCaster 2368 — 8y
Ad

Answer this question