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

Problem with my checker script?

I want this script to check if whatever hit it is a ball. If it is, it will make the door cancollide true. Otherwise, false. But all it does it make it cancollide false when a ball hits it. Help?

script.Parent.Touched:connect(function(hit)
	if hit.Parent.Name == "LobbyBall" then
		script.Parent.CanCollide = true
		wait(1)
		return
	else
		script.Parent.CanCollide = false
		wait(1)
		return
	end
end)

2 answers

✓ Accepted answer

Its because the parent is maybe the "workspace", hit mean like the part touched the part you want to touched.And don't forgot to add a debounce for not spamming the function.

You,re code here:

local debounce = false
script.Parent.Touched:connect(function(hit)
	if not debounce then
	debounce = true
  	  if hit.Name == "LobbyBall" then
       	 script.Parent.CanCollide = true
       	 wait(1)
       	 return
 	   else
      	  script.Parent.CanCollide = false
       	 wait(1)
       	 return
  	  end
wait(1)
debounce = false
	end
end)
script.Parent.Touched:connect(function(hit)
    if hit.Name == "LobbyBall" then --This is a part, we don't need to find it's parent. hit is the part.
        script.Parent.CanCollide = true
        wait(1)
        return
    else
        script.Parent.CanCollide = false
        wait(1)
        return
    end
end)

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