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

"Player" parameter

Asked by
Bloxks 30
10 years ago

Whoops, didn't see that I even used the parameter, however, you guys still helped me with it. Thanks and sorry for a unneeded question.

I'm having trouble with the player parameter. That means that when I ever use the player parameter, I get a error that "Player" is not a valid object. Is this parameter removed? Does it need something defined? When I do:

function joined(player)
    if player.TeamColor == "Blue" then
            print(player.Name .. "is in team blue!")
    end
end

I don't know any more about the error, but if someone would be able to help, please tell me what the error is and how to fix it.

Thank you in advance.

0
Try including some code. Unclear 1776 — 10y
0
Please provide more context to your problem User#11893 186 — 10y

3 answers

Log in to vote
0
Answered by 10 years ago

Define the player.

In a local script, you can get a player with game.Players.LocalPlayer.

In a normal script, if you're using a touched part, you can use :GetPlayerFromCharacter, or do the long way script.Parent.Parent....

You can also use the PlayerAdded and Player Removing Event.

game.Players.PlayerAdded:connect(function(player) -- You have the player!
print("this player "..player.Name"  has joined")
end)
Ad
Log in to vote
1
Answered by 10 years ago

Wow thank you for explaining to me.

Log in to vote
0
Answered by
nate890 495 Moderation Voter
10 years ago

The problem with your code is that you don't have a connection line that defines what player actually is, assuming that the code you provided is all the code you have.

To fix this and make player actually exist simply add a connection line.

function joined(player)
    if player.TeamColor == BrickColor.new("Blue") then
        print(player.Name .. "is in team blue!")
    end
end

game.Players.PlayerAdded:connect(joined) -- Our connection line

Another problem with your code that I noticed is that you're trying to compare a TeamColor (a BrickColor value) to a string. You must compare it to another BrickColor value. This is done by adding BrickColor.new() around the string. I'm also not aware of the color "Blue" existing, however, there is "Bright blue" and "Really Blue".

Good luck!

0
You should use comments (when you get them). Posting answers that aren't answers isn't a smart move, so avoid posting them. Unclear 1776 — 10y
0
"when you get them" otherwise I would have. Your concern is appreciated and I'll delete this post once you see this comment. Thanks. nate890 495 — 10y
0
You should delete this answer, as it isn't an answer. User#11893 186 — 10y
0
I'll delete it in a minute, but as you can see the least I could do is leave answers as I can't comment like you two lucky people. Quit rubbing it in my face. Joke intended. nate890 495 — 10y
View all comments (2 more)
0
Alrighty. Unclear 1776 — 10y
0
Oh, hay, he edited it. Time for me to make this "answer" an answer. nate890 495 — 10y

Answer this question