✓ Accepted answer
well, it depends, if you want to know when a specific part is in range, than this should work;
local function in_Range(part1,part2,range)
if (part1.Position - part2.Position).magnitude <= range then
return true
end
return false
end
debounce = false
while wait(0.5) do
if in_Range(game.Workspace.gate,game.Workspace.car,30) == true then
if debounce == false then debounce = true
game.Workspace.gate.CanCollide = false
wait(3)
game.Workspace.gate.CanCollide = true
debounce = false end
end
end
or, if you want to see if any part in a model is in range, then replace the last part with this;
while wait(0.5) do
if debounce == false then debounce = true
local carModel = game.Workspace.carModel:GetChildren()
for i = 1, #carModel do
if in_Range(game.Workspace.gate,carModel[i],30) == false then
debounce = false
break
end
end
if debounce == true then
game.Workspace.gate.CanCollide = false
wait(3)
game.Workspace.gate.CanCollide = true
end
debounce = false end
end
or if you want to know when any part at all is in range, I hate you.
1 comment
xD