Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can't Access Character Inside Function?

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

1 comment

0

You would need to do plr.Name == for every single name in there, otherwise you will see unexpected behavior.

1 answer

✓ Accepted answer

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

2 comments

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.

0

Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.