Hello I was working on my project recently it’s a normal mini-car that moves by its self there is another script that controls blocked ways and turning parts
What is blocked ways?
Car stops while there is something in front of him
What are turning parts?
There are some invisible parts that the car will be tweened to those turning parts(like cars are turning to another way)
Here is the script :
local stopregion
local partsinregion
local tweenservice = game:GetService("TweenService")
local debounce = false
local info = TweenInfo.new(
1,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local okparts = {
script.Parent.CheckPart1,
script.Parent.CheckPart2,
game.Workspace.TunnelSpawn1.CheckPart1,
game.Workspace.TunnelSpawn1.CheckPart2,
game.Workspace.TunnelSpawn2.CheckPart1,
game.Workspace.TunnelSpawn2.CheckPart2
}
while true do
wait(0)
stopregion = Region3.new(script.Parent.CheckPart1.Position, script.Parent.CheckPart2.Position)
partsinregion = game.Workspace:FindPartsInRegion3WithIgnoreList(stopregion, okparts, 100)
if #partsinregion >= 1 then
for i,v in ipairs(partsinregion) do
print(v.Name)
if v.Name == "TurnPart1" or v.Name == "TurnPart2" then
if debounce == false then
table.insert(okparts, v)
debounce = true
local tween = tweenservice:Create(script.Parent.CarBodyPart, info, {CFrame = v.CFrame})
tween:Play()
tween.Completed:Connect(function()
debounce = false
table.remove(okparts, 7)
end)
end
else
if v.Name == "Tunnel1" or v.Name == "Tunnel2" or v.Name == "Tunnel3" or v.Name == "Tunnel4" or v.Name == "Tunnel5" or v.Name == "Tunnel6" then
game.ReplicatedStorage.Happiness.Value = game.ReplicatedStorage.Happiness.Value + script.Parent.Happiness.Value
script.Parent:Destroy()
end
script.Parent.MoveCarScript.Disabled = true
script.Parent.CarBodyPart["idle car"].PlaybackSpeed = 1
repeat
wait(0)
stopregion = Region3.new(script.Parent.CheckPart1.Position, script.Parent.CheckPart2.Position)
partsinregion = game.Workspace:FindPartsInRegion3WithIgnoreList(stopregion, okparts, 100)
for i,v in ipairs(stopregion) do
if v.Name == "TurnPart1" or v.Name == "TurnPart2" then
table.insert(okparts, v)
wait(0.1)
table.remove(okparts, 7)
end
end
wait(0)
until #partsinregion == 0
script.Parent.MoveCarScript.Disabled = false
script.Parent.CarBodyPart["idle car"].PlaybackSpeed = 1.5
end
end
end
wait(0)
end
But when a car gets brokes after it turns, that car that back of the car gets stuck forever until it despawn
Now what should I do?