So I have a script that detects if another brick touches brick, I have the brick located in the players HumanoidRootPart. The problem with the script is that it also detects whenever your player touches it. I would just want to know if there is any way to make it so that it doesnt detect your own player touching it.
local plr = game.Players.LocalPlayer local char = plr.Character local HRP = char:WaitForChild("HumanoidRootPart") --Creating the part local Detector = Instance.new("Part") Detector.Position = Vector3.new(HRP.Position.X,HRP.Position.Y,HRP.Position.Z) Detector.Name = "Detector" Detector.Size = Vector3.new(5,2,5) Detector.Anchored = false Detector.Transparency = 0 Detector.CanCollide = true Detector.Parent = HRP --Weld local Weld = Instance.new("Weld", Detector) Weld.Part0 = HRP Weld.Part1 = Detector --Touched Function Detector.Touched:Connect(function(hit) if hit.Parent.ClassName == "Part" then --Do stuff here end end)
Use and hit.Parent ~= char
so it ignores the player's character
--Touched Function Detector.Touched:Connect(function(hit) if hit.Parent.ClassName == "Part" and hit.Parent ~= char then --Do stuff here end end)
The function IsA() should work
EXAMPLE:
Detector.Touched:connect(function(hit) if hit.Parent:IsA("Part") then -- Do stuff here end end)
this should work This IsA function checks for a certain class and ignores everything else so that should be the most efficient way.