Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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?

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. httpOmqCxpcake 70 — 7y
0
You maybe could just call he :MakeJoints() funcion on the model. FiredDusk 1466 — 7y

2 answers

Log in to vote
1
Answered by 7 years ago

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.

Ad
Log in to vote
0
Answered by 7 years ago

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
0
Leave an upvote if I helped! :) joritochip 705 — 7y
0
The :MakeJoints() is especially useful when the car uses hinges. Just learned this. Should be accepted as answer ;p httpOmqCxpcake 70 — 7y

Answer this question