I'm creating a little touch part to demonstrate a database system, the idea being every time you touch the part you get 5 points. Since the roblox touch system is a bit finnicky, I need a debounce which is pretty simple. My code is as follows;
local debounce = true TestPart.Touched:Connect(function(Part) if debounce == true then debounce = false print('ok') if Part.Parent:FindFirstChild('HumanoidRootPart') then -- code is here end wait(5) debounce = true end end)
When I touch this part the code doesn't run at all. Why is this happening and how can I solve it?
i use this code to test your code. And it works. Try to change the parameter to hit and btw i put this code inside the part
local TestPart = workspace.Part local debounce = true TestPart.Touched:Connect(function(hit) if debounce == true then debounce = false print('ok') if hit.Parent:FindFirstChild('HumanoidRootPart') then print("HumanoidPart") end wait(5) debounce = true end end)
It seems to me that your script is touching other non-humanoid parts so debounce is false at all times. Try only changing the debounce after a HumanoidRootPart is found.