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?
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 Name
of the Model
is one of the children of game.Players
, as in if game.Players[model.Name] then
(jav2612's answer)
Seeing if the Model
contains a Humanoid
called "Humanoid"
, as in if 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