Car spawn button not working

Hi!.I didn’t know how to name this, so here i put you in context. I’m trying to make a Car Spawn Button, but I can’t figure out why this happends.
Example Video
robloxapp-20201110-2310589.wmv (4.1 MB)

This is the script that the button uses.

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()

local clone = game.ReplicatedStorage:FindFirstChild("ButterFly"):Clone()

clone:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame + Vector3.new(15,0,0))

clone.Parent = game.Workspace

clone:MakeJoints()

end)

Any help to solve this will be apreciated.

I think I know what’s wrong with the script.

At the SetPrimaryPartCFrame line, you didn’t include (CFrame.new()). The script needs to look like this:

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()

local clone = game.ReplicatedStorage:FindFirstChild(“ButterFly”):Clone()

clone:SetPrimaryPartCFrame(CFrame.new(player.Character.HumanoidRootPart.CFrame + Vector3.new(15,0,0)))

clone.Parent = game.Workspace

clone:MakeJoints()

end)

Hope this helps!

1 Like

I tried it, but this happends

01:01:03.197 - Players.CRAFTRONIX_457.PlayerGui.HotBar.Cars.LocalScript:5: invalid argument #1 to ‘new’ (Vector3 expected, got CFrame)

Pretty sure you need to multiply it, so it’s relative.

player.Character.HumanoidRootPart.CFrame * Vector3.new(15,0,0)

Actually it might be

player.Character.HumanoidRootPart.CFrame * CFrame.new(15,0,0)

But idk, I forget how cframes work sometimes.

Okay yea, just checked. You need to do this:
clone:SetPrimaryPartCFrame(CFrame.new(player.Character.HumanoidRootPart.CFrame * Vector3.new(15,0,0)))