Help, the cars in my game randomly go "invisible"

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?

Oh it is thousands of studs away…

I have no idea how this happens? I mean they are welded together but sometimes they work other times they don’t and it is just so weird?

also this is the script

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

1 Like

Please use syntax

-- lua example

image
using ```

1 Like

alright thank you for the advice

1 Like

are you using weld constraints?

welds are like glue, the weld will destroy if the parts are separated

1 Like

First of all, your running one connection inf* times.

In your case I would use OOP, to do

OopExample.new(Car)

OopExample.Init()

2 Likes

my dev was the one who welded them, he did connect every part to the collission box but just the box

thank you, sent this to my dev and he said you had a point, any other feedback would be great !

1 Like

I would consider swapping to weld constraints unless the car is meant to break apart at one point

1 Like

alright I will ask him to do that, I remember also trying to do it with joints and it broke the same way so, I will ask them to try that

Welds only break, once Properties are changed inside the Model,
if he only is updating the Model:PivotTo() it should work perfectly.

But I know what he’s doing wrong on the PrimaryPart,
He’s updating the .CFrame inside there, instead of using Model:PivotTo(CFrame)

How to fix?
using CFrameValue that updates instead of CFrame from PrimaryPart.

2 Likes


It seems to work better but uh it can cause the same thing

Can you show the new code?

We are gonna try weld constraints alongside what Max said, see if they fix it

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

The script is still doing the same mistake with the tween.

1 Like
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 :slight_smile:

1 Like

thank you, imma send this to him

im starting to think its an issue with the physics engine or somethign cause there is no way…

You could try a few things;

Set StreamingEnabled to false. And/or…
car:SetPrimaryPartCFrame(CFrame.new(waypoint_B.Position - tweenOffset))

After entering Private Dms with that person,

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
1 Like