So I'm making a serving system, and I have this bit of code to prevent errors when somebody tries to click the passenger they want to serve. if localMouse.Target.Parent:FindFirstChild('Humanoid') then, this code doesn't work at all, I have no idea why, what is a better way to filter this?
✓ ANSWER ACCEPTED
Better way to filter if what I click is a player?
1 answer
✓ Accepted answer
This should work:
local PlayerS = game:GetService("Players")
local Target = Mouse.Target
if Target then
local Humanoid = Mouse.Target.Parent:FindFirstChild("Humanoid")
if Humanoid then
local Player = PlayerS:GetPlayerFromCharacter(Target.Parent)
if Player then
--code
end
end
end
:GetPlayerFromCharacter is always useful for situations like these.
This discussion is preserved as it was. New answers, comments, and votes are closed.
