In my homestore game I added fixed cars that go to point A to point B, however they have a weird habit of randomly “going invisible” that is, the collission box does the travel, but the actual car model stays in one place
Like here for example, I took the car that broke and placed it next to me, as you can see, the collission is normal but where is the car?
local badgeService = game:GetService("BadgeService")
local tweenService = game:GetService("TweenService")
local evilCars = workspace.MovingEvilCarsThatKill
local cars = evilCars.ActualCars
local waypoints = evilCars.Waypoints
local tweenOffset = Vector3.new(0,3,0)
local badgeId = 4321497985913155
local function MoveCar()
local car = cars:GetChildren()[math.random(1, #cars:GetChildren())]
local direction = math.random(1, 2)
local waypoint_A = waypoints:FindFirstChild("A"..direction)
local waypoint_B = waypoints:FindFirstChild("B"..direction)
local moveTweenInfo = TweenInfo.new(math.random(7, 10))
local moveTween = tweenService:Create(car.PrimaryPart, moveTweenInfo, {Position = (waypoint_B.Position - tweenOffset)})
local primaryPartCFrame = car:GetPrimaryPartCFrame()
if direction == 1 then
if car.CarRotated.Value == false then
car:SetPrimaryPartCFrame(primaryPartCFrame * CFrame.Angles(0, math.rad(180), 0))
end
car.CarRotated.Value = true
else
if car.CarRotated.Value then
car:SetPrimaryPartCFrame(primaryPartCFrame * CFrame.Angles(0, math.rad(-180), 0))
end
car.CarRotated.Value = false
end
car.PrimaryPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent.Humanoid.Health ~= 0 then
car.Hit:Play()
end
hit.Parent.Humanoid.Health = 0
if not badgeService:UserHasBadgeAsync(player.UserId, badgeId) then
badgeService:AwardBadge(player.UserId, badgeId)
end
end
end)
car.PrimaryPart.Position = (waypoint_A.Position - tweenOffset)
car.Parent = workspace
moveTween:Play()
moveTween.Completed:Wait()
car.Parent = cars
end
while true do
task.spawn(MoveCar)
task.wait(10)
end
Also sorry if this is the wrong place to post this, my dev adviced me to upload it here
local badgeService = game:GetService("BadgeService")
local tweenService = game:GetService("TweenService")
local evilCars = workspace.MovingEvilCarsThatKill
local cars = evilCars.ActualCars
local waypoints = evilCars.Waypoints
local tweenOffset = Vector3.new(0,3,0)
local badgeId = 4321497985913155
local function MoveCar()
local car = cars:GetChildren()[math.random(1, #cars:GetChildren())]
local carPivot = car:GetPivot()
local direction = math.random(1, 2)
local waypoint_A = waypoints:FindFirstChild("A"..direction)
local waypoint_B = waypoints:FindFirstChild("B"..direction)
local moveTweenInfo = TweenInfo.new(math.random(7, 10))
local moveTween = tweenService:Create(car.PrimaryPart, moveTweenInfo, {Position = (waypoint_B.Position - tweenOffset)})
if direction == 1 then
if car.CarRotated.Value == false then
car:PivotTo(carPivot * CFrame.Angles(0, math.rad(180), 0))
end
car.CarRotated.Value = true
else
if car.CarRotated.Value then
car:PivotTo(carPivot * CFrame.Angles(0, math.rad(-180), 0))
end
car.CarRotated.Value = false
end
car.PrimaryPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent.Humanoid.Health ~= 0 then
car.Hit:Play()
end
hit.Parent.Humanoid.Health = 0
if not badgeService:UserHasBadgeAsync(player.UserId, badgeId) then
badgeService:AwardBadge(player.UserId, badgeId)
end
end
end)
car.PrimaryPart.Position = (waypoint_A.Position - tweenOffset)
car.Parent = workspace
moveTween:Play()
moveTween.Completed:Wait()
car.Parent = cars
end
while true do
task.spawn(MoveCar)
task.wait(10)
end
local badgeService = game:GetService("BadgeService")
local tweenService = game:GetService("TweenService")
local evilCars = workspace.MovingEvilCarsThatKill
local cars = evilCars.ActualCars
local waypoints = evilCars.Waypoints
local tweenOffset = Vector3.new(0,3,0)
local badgeId = 4321497985913155
local vectr3 = Instance.new("Vector3Value")
local currentcar =nil
vectr3:GetPropertyChangedSignal(`Value`):Connect(function()
if currentcar then
currentcar:MoveTo(vectr3.Value)
end
end)
local function MoveCar()
currentcar=nil
local car = cars:GetChildren()[math.random(1, #cars:GetChildren())]
currentcar = car
local carPivot = car:GetPivot()
local direction = math.random(1, 2)
local waypoint_A = waypoints:FindFirstChild("A"..direction)
local waypoint_B = waypoints:FindFirstChild("B"..direction)
local moveTweenInfo = TweenInfo.new(math.random(7, 10))
vectr3.Value = car.PrimaryPart.Position
local moveTween = tweenService:Create(vectr3, moveTweenInfo, {Value = (waypoint_B.Position - tweenOffset)})
if direction == 1 then
if car.CarRotated.Value == false then
car:PivotTo(carPivot * CFrame.Angles(0, math.rad(180), 0))
end
car.CarRotated.Value = true
else
if car.CarRotated.Value then
car:PivotTo(carPivot * CFrame.Angles(0, math.rad(-180), 0))
end
car.CarRotated.Value = false
end
car.PrimaryPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent.Humanoid.Health ~= 0 then
car.Hit:Play()
end
hit.Parent.Humanoid.Health = 0
if not badgeService:UserHasBadgeAsync(player.UserId, badgeId) then
badgeService:AwardBadge(player.UserId, badgeId)
end
end
end)
car.PrimaryPart.Position = (waypoint_A.Position - tweenOffset)
car.Parent = workspace
moveTween:Play()
moveTween.Completed:Wait()
car.Parent = cars
end
while true do
task.spawn(MoveCar)
task.wait(10)
end
Note that this wont work perfectly, because roblox is horrible
local BDGService = game:GetService("BadgeService")
local badgeId = 4321497985913155
local module = require(script.ModuleScript)
task.wait(3)
local newCar: module.Car = {
Car = game.ReplicatedStorage.Assets.Car1,
CFrameValue = Instance.new("CFrameValue")
}
newCar.Car.Parent = workspace.Cars
newCar.CFrameValue:GetPropertyChangedSignal('Value'):Connect(function()
newCar.Car:PivotTo(newCar.CFrameValue.Value)
end)
newCar.Car.PrimaryPart.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
plr.Character.Humanoid.Health = 0
if BDGService:UserHasBadgeAsync(plr.UserId,badgeId) then
return
end
BDGService:AwardBadge(plr.UserId,badgeId)
end
end)
module.Drive(newCar)
export type Car = {
Car: Model,
CFrameValue: CFrameValue
}
local WayPoints = workspace.WP
local Car = {}
function Car.Drive(car : Car)
local StartWayPoint = WayPoints.PPT1
local CarSpeed = 45
local tweeninfo = TweenInfo.new()
car.CFrameValue.Value = StartWayPoint.CFrame
for i=2, #WayPoints:GetChildren() do
local distance = (StartWayPoint.Position-WayPoints["PPT"..i].Position).Magnitude
local tweeninfo = TweenInfo.new(distance/CarSpeed,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut)
local tween = game:GetService("TweenService"):Create(car.CFrameValue,tweeninfo,{Value = WayPoints["PPT"..i].CFrame})
tween:Play()
tween.Completed:Wait()
end
end
return Car