Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to detect player touch part in Local Script?

Like the title says, I want to detect if the player is touching a part. I know how to do this in a Script, but I need it to be in a local script, so it gets triggered per player. Does anyone know how?

Script attached to No-Collision Part

local self = script.Parent

local function OnPartTouched(coll)
	local partParent = coll.Parent

	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		if can_touch == true then
			-- Code here
		end
	end
end

self.Touched:Connect(OnPartTouched)

4 comments

0

What you're doing can be done in a script.

0

self is already a keyword, change it to part or something else in the first line variable name

0

and script does the same thing

0

@Xapelize Self is not the issue. The code above works perfectly fine.

1 answer

✓ Accepted answer

Local Scripts don't work in the workspace so the code won't run. Put the local script somewhere it's able to run. You can view this page here on the Roblox developer site to see where local scripts are able to run code.

1 comment

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.