Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

2 comments

0

Where do I have to put this code?

0

repace it with line 15-22

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.