Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to detect player touch part in Local Script?

Asked by 2 years ago

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)
0
What you're doing can be done in a script. MarkedTomato 810 — 2y
0
self is already a keyword, change it to part or something else in the first line variable name Xapelize 2658 — 2y
0
and script does the same thing Xapelize 2658 — 2y
0
@Xapelize Self is not the issue. The code above works perfectly fine. EightBlits 7 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago

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.

0
Thank you! EightBlits 7 — 2y
Ad

Answer this question