So I started making a racing game, and I added a invisible block at the beginning of the race. This block will start a stopwatch at the top of the players screen. This is the code:
local stopwatch = 0 local Debounce = false function stopWatchstart() while true do stopwatch = stopwatch + 1 wait(1) script.Parent.Text = (stopwatch.."") end end game.Workspace.StartStopwatch.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if Debounce == false then Debounce = true stopWatchstart() wait(5) Debounce = false end end end)
The thing is I have the part set to cancollide false (so the player can go through). But then it doesn't start the stopwatch. How do I fix this?
Not really sure if this would help but try this. Block is your non-collidable part.
if block.Collide == true and hit.Parent:FindFirstChild("Humanoid") then if Debounce == false then Debounce = true stopWatchStart() wait(5) Debounce = false end end
Collision won't affect touched. just make sure basepart.cantouch is on.
local stopwatch = 0 local Debounce = false function stopWatchstart() local functionLoop = coroutine.wrap(function() -- put this here in case loop is stopping script forever while true do stopwatch = stopwatch + 1 wait(1) script.Parent.Text = (stopwatch.."") end end) functionLoop() end game.Workspace.StartStopwatch.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if Debounce == false then Debounce = true stopWatchstart() wait(5) Debounce = false end end end)