Here is my code:
local debounce = false local function Hurt(Part) if debounce == false then print "check1" if Part.Name == "box" then print "check2" Part.Position = Vector3.new(0, 3, 0) debounce = true game.Workspace.Baseplate.BrickColor = BrickColor.new("Institutional white") wait(0.5) game.Workspace.Baseplate.BrickColor = BrickColor.new("Pearl") debounce = false end end end script.Parent.Touched:connect(Hurt)
There is a box that the player pushes to touch borders around a specific area. This is the script in the borders. When the box is pushed and touches the border, it works the first time it is pushed to the border, but doesn't work when the box is pushed to the same border again. Any suggestions?
Debounce. That is pretty much all I have to say.
So your script might be firing but not finding the debounce. To fix this:
if debounce == false then debounce = true print("check1") end wait(0.5) debounce = false
Note that you have the reset in your script, you'll need to move it and anything after. Also, you'll want to change the deboucne to true before anything happens with the script. This will make sure that the function won't fire several times before the part is even found.
However, the script might not be firing at all. To check:
local function Hurt(Part) print("Function ran") end
Theoretically, this should answer your question. If it doesn't please tell me and I'll hop on Studio ASAP to fix it.
EDIT:
So your script isn't detecting the Part's name. You can add
else print(Part.Name) end
to your if statement to check what the function is finding. Something you can try is to look at the hitting part's parent and find "box":
if Part.Parent then if Part.Parent:FindFirstChild("box") then end end
These 2 if statements would replace your current if part.Name statement.
I hope this now answers your question