Car's collision group changes to default after i regen it

  1. What is the issue? The car parts’ collision groups go back to default after i regen the car

  2. What solutions have you tried so far? I tried to look on the devforum but did not find the solution

local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")
local Vehicles = workspace:WaitForChild("Vehicles")
local RS = game:GetService("ReplicatedStorage")
local Event = RS:WaitForChild("Loaded")
local Characters = "Characters"
local Body = "Body"
local Wheels = "Wheels"

PhysicsService:RegisterCollisionGroup(Characters)
PhysicsService:RegisterCollisionGroup(Wheels)
PhysicsService:RegisterCollisionGroup(Body)

PhysicsService:CollisionGroupSetCollidable(Body,Wheels,false)
PhysicsService:CollisionGroupSetCollidable(Body,Characters,false)
local function onDescendantAdded(descendant)
	if descendant:IsA("BasePart") then
		descendant.CollisionGroup = Characters
	end
end

local function onCharacterAdded(character)
	for _, descendant in pairs(character:GetDescendants()) do
		onDescendantAdded(descendant)
	end
	character.DescendantAdded:Connect(onDescendantAdded)
end

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end)

Event.OnServerEvent:Connect(function()

	for i,v in pairs(Vehicles:GetChildren()) do
		print(v.Name)
		for i,v in pairs(v.Car.Body:GetDescendants()) do
			if v:IsA("BasePart") then
				v.CollisionGroup = Body 
			end
		end
		for i,v in pairs(v.Car.Wheels:GetDescendants()) do
			if v:IsA("BasePart") then
				v.CollisionGroup = Wheels
			end
		end
	end

end)

im using collision groups to make cars bulletproof

2 Likes

anyone has a working fix for that?

Are you getting the cloned vehicle from somewhere else, such as ReplicatedStorage?

i have an event in replicated storage and in replicatedfirst there is a script that fires the event when the game fully loads, sorry for the late response

1 Like

You should put the script from ReplicatedFirst, into ServerScriptService. The script is better stored that way. Also, what is the event for, for when it gets fired?

I use the event to not use WaitForChild() but i dont know why, im really confused with my script

The vehicle folder is in workspace and each car has a spawn button

That didn’t really explain, what the event is supposed to trigger for. If your copying the same vehicle from Workspace and not anywhere else, then the Collison groups should stay the same. At least I think.

The problem is inside of the regen script i guess
image

location = script.Parent.Parent.Parent

regen = script.Parent.Parent

save = regen:clone()

function onClicked()

regen:remove()

back = save:clone()

back.Parent = location

back:MakeJoints()

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Are you able to show us the Collison groups for the vehicle?


here

i think i know how to fix this, sorry if im wasting your time

1 Like

What do also, the Collison groups look like after the vehicle has been regenerated? Don’t worry, your wasting nobody’s time.

all the parts of my car get their collision group resetted to default after regen, collision groups themselves dont change

1 Like

You should replace the 9th line with a local instead:

local back = save:clone()

You should also try re-setting the Collison groups after the car has been respawned. Reply if you need help with that.

Thanks, i will try re setting the collision groups

1 Like

Has it worked or has it caused new problems?

1 Like

It doesnt work at all im just sitting and overthinking everything over and over again

What does the new regen button script look like? I’ll see if I can help.

1 Like

Would you mind if i send you a place file and you review it? It’s hard to show you the files