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

Spawning vehicle in a certain spot?

Asked by
Pvzw 19
6 years ago

I have been trying to spawn a vehicle. It works, but when I try to get it to spawn in a certain spot like a spawner part, it doesn't seem to comply.

This is code

script.Parent.MouseButton1Click:connect(function(GetCar)
        Mod = game.ServerStorage["Dodge Charger"]
        local clone = Mod:clone()
        clone.Parent = workspace
        clone.CFrame = script.Parent.Parent.Parent.Parent.Parent.SpawnPart.CFrame
        clone:MakeJoints()
        script.Parent.Parent.Parent:Destroy()
end)

Fyi, it is a GUI textbutton.

2 answers

Log in to vote
2
Answered by 6 years ago

I'm going to assume that your car is a model and not just a singular part. If that is the case, then you aren't able to use CFrame on a model. That is only for single BaseParts. If you are wanting to move a model either use MoveTo or SetPrimaryPartCFrame.

https://wiki.roblox.com/index.php?title=API:Class/Model/MoveTo https://wiki.roblox.com/index.php?title=API:Class/Model/SetPrimaryPartCFrame

Ad
Log in to vote
0
Answered by 6 years ago

Your script is a local script. ServerStorage cannot be accessed by the client. Place the model in ReplicatedStorage so the client can access it.

local sP = script.Parent.Parent
local sP2 = sP.Parent.Parent

script.Parent.MouseButton1Click:Connect(function() -- :connect is deprecated, switch to :Connect
        Mod = game:GetService("ReplicatedStorage")["Dodge Charger"]
        local clone = Mod:Clone() -- :clone is deprecated, switch to :Clone
        clone:SetPrimaryPartCFrame(sP2.SpawnPart.CFrame) -- make sure to set a primary part!
        clone.Parent = workspace
        clone:MakeJoints()
        sP.Parent:Destroy()
end)

Answer this question