I want to make an if statement that goes something along the lines of "if brick is a player, then do..." but I don't know how to differentiate between a normal brick and a character. Any help?
Nooby question: How to target player?
2 answers
In ROBLOX a Character is actually a Model - a collection of specific Instances such as Part, Humanoid, etc...
There are multiple ways to identify whether any given Model is a Player's Character, but the 2 most popular are:
Seeing if the
Nameof theModelis one of the children ofgame.Players, as inif game.Players[model.Name] then(jav2612's answer)Seeing if the
Modelcontains aHumanoidcalled"Humanoid", as inif model:FindFirstChild("Humanoid") then
Checking if a specific Part is a Player is slightly different because you need to check whether the Model that it belongs to is a Player's Character, rather than the Model itself - but this is easy to do with the Parent property!
You could also write this as a function so that you can easily check if a brick is a constituent part of a Player's Character from elsewhere in the script:
function IsPlayer(part)
if part.Parent:FindFirstChild("Humanoid") then return true end
return false
end
--You might use it like this
if IsPlayer(someRandomPart) then
--someRandomPart belongs to a player!
end
brick = TheBrick
players = game:GetService("Players")
if players:FindFirstChild(brick.Parent.Name) ~= nil then
print("Le brick is a player.")
else
print("Its just a brick....")
end
11 comments
if your using a Touched event then your going to need to do brick.Parent.Name to get the name of the character.
A Player's character will not be a Brick (Part) unless the OP is using custom characters, which I don't think he is. You need to use brick.Parent.Name instead, I do believe.
Thats what I just said....
I edited it so it should work now.
I'm not sure I understand Line 4 of your script. I pasted this script into TheBrick along with the Touched event, but every time I touched it with my character it returned "Its just a brick".
You have to define "TheBrick".... Obviously you cant just leave it the way it is. As for line 4, basically it checks to see if the character has a player associated with them.
Yes, I already did replace "TheBrick" with the name of my brick (duh :P). So Line 4 is saying "if you find a child in 'players' not named 'Workspace', then print #1, but if you do find it, print #2?
Actually, what does ~= mean? I know = and == but can't remember ~=.
~= means not equal to. This script checks to see if a player with the same name as the brick's parent is not equal to nil, which means it exists. When a part of your character touches it you have to find the part's parent's name which is the characters name. Thats why you do part.Parent.
But the part's parent is Workspace, so what you are asking is if a player has the same name as Workspace?
No.... The parent of a torso or head or arms/legs are the character's Model. It takes the name of the character and looks for the player with the same name.
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
This would only tell if the model has a humanoid.... Lots of models use humanoids but dont have players. You will need to check Players to see if a player is associated with the character.
I suggested that as a possibility as well, I only demonstrated one of them in code because your answer covered the other option.
When I tried to use the IsPlayer function it returned the error "attempt to call global 'IsPlayer' (a nil value)".
You need to have the definition of the function in the script, it's not part of the roblox API.
Oh, I see. This is my first time creating a custom function. When I add the definition it now works. Thanks!