2

# 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!

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

0

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.

0
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
0
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)