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

"Player" parameter

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.

2 comments

0

Try including some code.

0

Please provide more context to your problem

3 answers

✓ Accepted answer

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)

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!

6 comments

0

You should use comments (when you get them). Posting answers that aren't answers isn't a smart move, so avoid posting them.

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.

0

You should delete this answer, as it isn't an answer.

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.

0

Alrighty.

0

Oh, hay, he edited it. Time for me to make this "answer" an answer.

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