Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make it so that my car doesnt break apart when i spawn it in from the car dealership?

so i have the script to spawn in the car...

local dialog = script.Parent dialog.DialogChoiceSelected:connect(function(player, choice)

local stats = player.Backpack:FindFirstChild('Stats')
if not stats then return end


local Money = stats:FindFirstChild('Money')
if not Money then return end

if choice == script.Parent.DialogChoice.Car then
    if Money.Value >= 1000 then 
        game.ReplicatedStorage.Car:Clone().Parent = game.Workspace
        Money.Value = Money.Value - 1000 
    end

this script works and it makes the car spawn in but no matter what car i use everytime i spawn it in while playing it just breaks apart, can someone help me please?

2 comments

0

Did you try welding it? If you unanchor it without cloning it, does it break apart? If so, weld it. If not, I have no idea, but maybe try anchoring it first, then weld, finally unanchor.

0

You maybe could just call he :MakeJoints() funcion on the model.

2 answers

Just knew that :clone removes welding and such.. (Quite a beginner myself)

I made a really basic car. I combined that into a model, moved it to ReplicatedStorage, named it "Car" like you have done.

I simply inserted a Weld Script I found in the toolbox..

local prev
local parts = script.Parent:GetChildren()
for i = 1,#parts do
	if ((parts[i].className == "Part") or (parts[i].className == "SpawnLocation") or (parts[i].className == "Seat") or (parts[i].className == "TrussPart") or (parts[i].className == "VehicleSeat")) then
		if (prev ~= nil) then
			local weld = Instance.new("Weld")
			weld.Part0 = prev
			weld.Part1 = parts[i]
			weld.C0 = prev.CFrame:inverse()
			weld.C1 = parts[i].CFrame:inverse()
			weld.Parent = prev
			parts[i].Anchored = false
		end
		prev = parts[i]
	end
end
wait(3)

I made a script to clone the car to the workspace(Your code)

game.ReplicatedStorage.Car:Clone().Parent = game.Workspace

It it cloned, then the weld script welds the entire model..

I then unanchored the model, it has physics and won't break apart.

Although TESTsubject0100's answer should work, there's a better way to do it.

local stats = player.Backpack:FindFirstChild('Stats')
if not stats then return end

local Money = stats:FindFirstChild('Money')
if not Money then return end

if choice == script.Parent.DialogChoice.Car then
	if Money.Value >= 1000 then 
		local Car = game.ReplicatedStorage.Car:Clone()
		Car.Parent = game.Workspace
		Car:MakeJoints()
		Money.Value = Money.Value - 1000 
	end
end

2 comments

0

Leave an upvote if I helped! :)

0

The :MakeJoints() is especially useful when the car uses hinges. Just learned this. Should be accepted as answer ;p

This discussion is preserved as it was. New answers, comments, and votes are closed.