so i have the script to spawn in the car...
local dialog = script.Parent dialog.DialogChoiceSelected:connect(function(player, choice)
01 | local stats = player.Backpack:FindFirstChild( 'Stats' ) |
02 | if not stats then return end |
03 |
04 |
05 | local Money = stats:FindFirstChild( 'Money' ) |
06 | if not Money then return end |
07 |
08 | if choice = = script.Parent.DialogChoice.Car then |
09 | if Money.Value > = 1000 then |
10 | game.ReplicatedStorage.Car:Clone().Parent = game.Workspace |
11 | Money.Value = Money.Value - 1000 |
12 | 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?
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..
01 | local prev |
02 | local parts = script.Parent:GetChildren() |
03 | for i = 1 ,#parts do |
04 | 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 |
05 | if (prev ~ = nil ) then |
06 | local weld = Instance.new( "Weld" ) |
07 | weld.Part 0 = prev |
08 | weld.Part 1 = parts [ i ] |
09 | weld.C 0 = prev.CFrame:inverse() |
10 | weld.C 1 = parts [ i ] .CFrame:inverse() |
11 | weld.Parent = prev |
12 | parts [ i ] .Anchored = false |
13 | end |
14 | prev = parts [ i ] |
15 | end |
16 | end |
17 | wait( 3 ) |
I made a script to clone the car to the workspace(Your code)
1 | 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.
01 | local stats = player.Backpack:FindFirstChild( 'Stats' ) |
02 | if not stats then return end |
03 |
04 | local Money = stats:FindFirstChild( 'Money' ) |
05 | if not Money then return end |
06 |
07 | if choice = = script.Parent.DialogChoice.Car then |
08 | if Money.Value > = 1000 then |
09 | local Car = game.ReplicatedStorage.Car:Clone() |
10 | Car.Parent = game.Workspace |
11 | Car:MakeJoints() |
12 | Money.Value = Money.Value - 1000 |
13 | end |
14 | end |