Ad
Log in to vote
2

Function not firing when this part is touched?

Asked by 1 year 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 55 — 1y
0
except I did use the Touched event Littlebigplanet40000 55 — 1y

4 answers

Log in to vote
0
Answered by 1 year 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 1 year ago
Edited 1 year 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 55 — 1y
Log in to vote
0
Answered by
tjtorin 171
1 year 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 1 year ago

remove local because local used for variables not functions

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

Answer this question