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

Function not firing when this part is touched?

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!

2 comments

0

The same thing is happening to me.

0

except I did use the Touched event

4 answers

✓ Accepted answer

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.

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)

``

1 comment

0

I don't know how to use a code block btw

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)

remove local because local used for variables not functions

1 comment

1

It would still work. Functions are variables too.

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