Basically, I am making a car shop, shown here http://prntscr.com/6bx9ln and when you click one of those buttons a buy button appears at the right panel. That works, but my problem is with the buy button. When I click the buy button the car spawns and then crumbles, the script is here.
player = script.Parent.Parent.Parent.Parent.Parent cost = 5000 script.Parent.MouseButton1Click:connect(function() leaderstats = player:FindFirstChild("leaderstats") if leaderstats then money = leaderstats:FindFirstChild("Money") if money then if money.Value >= cost then spawncar = game.Lighting["CiviCar"]:clone() spawncar.Parent = workspace spawncar.MakeJoints() player.leaderstats.Money.Value = player.leaderstats.Money.Value - 5000 script.Parent.Text = "Bought" else script.Parent.FontSize = 14 script.Parent.Text = "Not enough $" return end end end end)
So yes, this spawns the car, and takes the money away but the car crumbles when spawned. This is the heirachy http://prntscr.com/6jjrbw and and this is the heirachy of the brick that when touched brings up the whole GUI http://prntscr.com/6jjrkx. Thanks.
Like what aquathorn321 said. You need to make joints. However how he did it is incorrect. MakeJoints is a function, therefore you do not use MakeJoints like this: part.MakeJoints()
but like this: part:MakeJoints
. You also did this in your script.
player = script.Parent.Parent.Parent.Parent.Parent cost = 5000 script.Parent.MouseButton1Click:connect(function() leaderstats = player:FindFirstChild("leaderstats") if leaderstats then money = leaderstats:FindFirstChild("Money") if money then if money.Value >= cost then spawncar = game.Lighting:FindFirstChild("CiviCar"):clone() --Use FindFirstChild or WaitForChild instead. local weld = Instance.new("Weld", spawncar.Seat) --Change this to any part in the car with a unique name. If your car already has welds, remove this line! spawncar.Parent = workspace spawncar:MakeJoints() --You need welds to actually use :MakeJoints(). MakeJoints is a function! Use ":" instead of "." like as if it's a property! player.leaderstats.Money.Value = player.leaderstats.Money.Value - 5000 script.Parent.Text = "Bought" else script.Parent.FontSize = 14 script.Parent.Text = "Not enough $" return end end end end)
Hope it helps!
If it crumbles, then the problem is with the joints, therefore you should look over the piece of the code where you establish the joints. Line 12 reads spawn.MakeJoints()
when it should read spawncar:MakeJoints()
.
Finished Script
local player = game.Players.LocalPlayer --Assuming the script is a localscript, you can shorten this. local cost = 5000 script.Parent.MouseButton1Click:connect(function() local leaderstats = player:FindFirstChild("leaderstats") --You don't need nearly as many if statements as you had, since if the code results in error, it will stop running and can be recalled when the button is pressed again. local money = leaderstats:FindFirstChild("Money") if money.Value >= cost then local spawncar = game.Lighting["CiviCar"]:clone() spawncar.Parent = workspace spawncar:MakeJoints() --Assuming you already have proper welds established in the car. money.Value = money.Value - 5000 script.Parent.Text = "Bought" else script.Parent.FontSize = 14 script.Parent.Text = "Not enough $" end end)