Check if player walked through a part

I want to check if a player went through the doors. Not sure how can I do that.
image

Code. Yes, I know i couldve done local part = script.Parent.Parent.Parent.Parent

local Players = game:GetService("Players")

script.Parent.Parent.Parent.Enter.Triggered:Connect(function(p)
	local userId = p.UserId
	local thumbType = Enum.ThumbnailType.HeadShot
	local thumbSize = Enum.ThumbnailSize.Size48x48
	local success, err = pcall(function()
		local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
		script.Parent.Image.Image = content
		script.Parent.Parent.Parent.pName.pName.Text = p.Name
		script.Parent.Parent.Parent.Parent.Doors.CanCollide = false
		script.Parent.Parent.Parent.Parent.Signal.Color = Color3.fromRGB(75, 151, 75)
		script.Parent.Parent.Parent.Parent.Signal2.Color = Color3.fromRGB(75, 151, 75)
		task.wait(5)
		script.Parent.Image.Image = 0
		script.Parent.Parent.Parent.Parent.Doors.CanCollide = true
		script.Parent.Parent.Parent.pName.pName.Text = ""
		script.Parent.Parent.Parent.Parent.Signal.Color = Color3.fromRGB(255, 0, 0)
		script.Parent.Parent.Parent.Parent.Signal2.Color = Color3.fromRGB(255, 0, 0)
	end)
	if not success then
		print("Problem showing user's image. "..err)
	end
end)```
1 Like

Connect a touched event to the part, and then use :GetTouchingParts(). This is what I mean:

print(part:GetTouchingParts()) --> {}
part.Touched:Connect(function() end)
print(part:GetTouchingParts()) --> {BasePart}

You need to ensure the part has a TouchInterest, or else it won’t care what it’s touching. To make a TouchInterest, connect the Touched event!

1 Like

Thanks. This is what I needed.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.