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

Why Doesn't the Parameter "player" Work?

I've seen multiple scripts use the parameter "player" to access the Local Player easily, without need of a local script. I tried to use it myself. But with my luck it didn't work. This is what I tried:

function added(player)
	player.Character.Humanoid.WalkSpeed = 0
end

game.Players.PlayerAdded:connect(added)

Not sure why it didn't work, and every time I test it the output displays either: Workspace.Script:2: attempt to index field 'player' (a nil value) or Workspace.Script:2: attempt to index field 'Character' (a nil value)

I have no idea why it's not working. I thought it might have been just an issue with ROBLOX Studio but to my surprise I inserted takecover's Intro Gui Plugin, a script that uses the "player" parameter, and it worked. Weird how it works in takecover's Plugin, but not my script. Any help would much appreciated. Thanks!

3 comments

0

This is in a localscript?

0

First you need a "CharacterAdded" example: player.CharacterAdded:connect(function(NAME HERE) right after the "Added" part.

0

Not in a local script. It's in a normal script in the workspace.

1 answer

✓ Accepted answer

Try this:

function added(player)
	player.CharacterAdded:connect(function() --Makes sure that the character is loaded in.
		player.Character.Humanoid.WalkSpeed = 0
	end)
end

game.Players.PlayerAdded:connect(added)

This should work now. The only problem was that the function was firing before the character was loaded in, so you were basically telling the game to go to a nil object. Anyways, if you have any questions or problems, leave a comment below. Hope this helped :P

2 comments

0

Yup, that worked flawlessly. Thanks a bunch!

0

Haha, no prob. Glad I could help :P

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