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

Can't Access Character Inside Function?

Asked by 5 years ago

I have this script, so that if any of the developers of my game join, they can walk very quickly. Here's what I have:

game.Players.PlayerAdded:Connect(function(plr)
    if plr.Name == "FlippinAwesomeCrew" or "SuperVenomSwag" or "poisonbcm" or "AnimalLover07013" then
        plr.Character.Humanoid.WalkSpeed = 50
    end
end)

When I run this though, it runs an error saying: 18:00:48.648 - Workspace.Script:3: attempt to index field 'Character' (a nil value)

Any idea what I'm doing wrong and how to fix it.

Thank you for your help, and even if you can't help, thank you for your time.

Much Appreciated

0
You would need to do plr.Name == for every single name in there, otherwise you will see unexpected behavior. theCJarmy7 1293 — 5y

1 answer

Log in to vote
1
Answered by
Leamir 3138 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Hello, FlippinAwesomeCrew!

Basically what I did was make the server wait for the character and now it works!

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function()
        if plr.Name == "FlippinAwesomeCrew" or "SuperVenomSwag" or "poisonbcm" or "AnimalLover07013" then
        plr.Character.Humanoid.WalkSpeed = 50
        end
    end)
end)

Good Luck with your games

0
Hey, thanks for the help, I'll accept the answer, but you did one thing wrong. Instead of writing: game.Players.CharacterAdded, you should have written: plr.CharacterAdded, because I already used that paramater in the previous function. Besides that, thanks a lot man. FlippinAwesomeCrew 62 — 5y
0
Thanks Leamir 3138 — 5y
Ad

Answer this question