Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to detect if a player touches a none collidable block?

Asked by
friso9 -3
3 years ago

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?

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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
0
Where do I have to put this code? friso9 -3 — 3y
0
repace it with line 15-22 Mafincho 43 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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)

Answer this question