I’m trying to get my script to trigger a while loop to stop, if another part is touching the main part
local part = script.Parent
debounce = true
if debounce == true then
function onTouch(part)
if part.Parent:WaitForChild("OtherPart") then
print(part,"Touched")
debounce = false
end
end
function onTouchEnded(part)
if part.Parent:FindFirstChild("OtherPart") then
print(part,"Touched Ended")
--debounce = true is left like this for testing
end
end
part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)
end
while debounce == true do
part.BrickColor = BrickColor.Random()
end
debounce = true
function onTouch(part)
if debounce then
if part.Parent:WaitForChild("OtherPart") then
print(part,"Touched")
debounce = false
end
end
end
function onTouchEnded(part)
if part.Parent:FindFirstChild("OtherPart") then
print(part,"Touched Ended")
--debounce = true is left like this for testing
end
end
part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)
while debounce do
part.BrickColor = BrickColor.Random()
end
Hey there, sorry if it’s been a while and I don’t know if you solved this, here is a fix.
local part = script.Parent
debounce = false
function onTouch(part)
if part.Parent:WaitForChild("OtherPart") then
print(part,"Touched")
debounce = true
end
end
function onTouchEnded(part)
if part.Parent:FindFirstChild("OtherPart") then
print(part,"Touched Ended")
debounce = false
end
end
part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)
while true do
wait()
if debounce == true then
part.BrickColor = BrickColor.Random()
end
end