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

Why Doesn't the Parameter "player" Work? [closed]

Asked by 9 years ago

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!

0
This is in a localscript? DigitalVeer 1473 — 9y
0
First you need a "CharacterAdded" example: player.CharacterAdded:connect(function(NAME HERE) right after the "Added" part. woodengop 1134 — 9y
0
Not in a local script. It's in a normal script in the workspace. sidekick83 80 — 9y

Locked by Redbullusa and M39a9am3R

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
9 years ago

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

0
Yup, that worked flawlessly. Thanks a bunch! sidekick83 80 — 9y
0
Haha, no prob. Glad I could help :P dyler3 1510 — 9y
Ad