I’m trying to make a scanner where when you touch the part , results come up on a screen.
I can’t work out how I get it to register the hit , and the player who hit.
Could someone help out please?
You want to listen for a Touched event. That event will fire for a part whenever something touches it, and the other part will be passed in as a parameter. Since the part touching the scanner will be a body part of a player, you would check to see if the parent of the touching part is a player’s character.
local function touchListener(partThatTouched)
local char = partThatTouched.Parent
-- We have to search for a player because we can't always assume
-- that whatever touched the brick was one.
local player = game.Players:GetPlayerFromCharacter(char)
if (player ~= nil) then
print("Player: "..player.Name.." touched the scanner.")
else
print("Something touched the scanner but it wasn't a player.")
end
end
scannerPart.Touched:Connect(touchListener)
1 Like
You can do something like
script.Parent.Touched:Connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
-- do whatever you want
end
end)
1 Like