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

Function not firing when this part is touched?

Asked by 3 years ago
local function onTouch(otherPart)
        otherPart.Anchored = true
        local Humanoid = otherPart.Parent:FindFirstChild("Humanoid")
        if Humanoid then
            otherPart.Anchored = false
            print("WORK. JUST WORK")
        end
    end

I put this script inside a part, that whatever touches it shall become anchored. If otherPart is a player, then it should print. "WORK. JUST WORK." But it's not working. I'd love some help on this, thanks guys!

0
The same thing is happening to me. Littlebigplanet40000 77 — 3y
0
except I did use the Touched event Littlebigplanet40000 77 — 3y

4 answers

Log in to vote
0
Answered by 3 years ago

Add the following code at the bottom.

script.Parent.Touched:Connect(onTouch(hit))

You can replace 'hit' with 'otherPart' or anything else, it's really up to you.

Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

I think it could be a ROBLOX STUDIO problem. Cause i was doing this yesterday and it was working fine, but now i did it today it didn't work at all. I was trying this script a few minutes ago and it wasn't working.
`` function win() game.StarterGui.FinishedGame.TextLabel.Visible = true end

script.Parent.Touched:Connect(win)

``

0
I don't know how to use a code block btw Littlebigplanet40000 77 — 3y
Log in to vote
0
Answered by
tjtorin 172
3 years ago

You need to add the Touched event for the function to fire

local function onTouch(otherPart)
        otherPart.Anchored = true
        local Humanoid = otherPart.Parent:FindFirstChild("Humanoid")
        if Humanoid then
            otherPart.Anchored = false
            print("WORK. JUST WORK")
        end
    end
script.Parent.Touched:Connect(onTouch)
Log in to vote
-1
Answered by 3 years ago

remove local because local used for variables not functions

1
It would still work. Functions are variables too. nikoviking 236 — 3y

Answer this question