Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make the car/model spawn at my Character CFrame?

    --Server script inside the Server Script Service:

player=game.Players.LocalPlayer

Car = game.ServerStorage.Model

CarClone=Car:Clone()

--Change test to whatever you have named the item you want to spawn

game.ReplicatedStorage.SpawnCar.OnServerEvent:Connect(function()

CarClone.Parent = game.Workspace

CarClone:MakeJoints()

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

end)

    -------Local script inside a text button in starter Gui:
    local player=game.Players.LocalPlayer
    
    local Car = game.ReplicatedStorage.Model
    
    local CarClone=Car:Clone()
    
    script.Parent.MouseButton1Click:Connect(function()
    
    game.ReplicatedStorage.SpawnCar:FireServer()
    
      
    
    player=game.Players.LocalPlayer
    
    Car = game.ReplicatedStorage.Model
    
    CarClone=Car:Clone()
    
    --Change test to whatever you have named the item you want to spawn
    
    game.ReplicatedStorage.SpawnCar.OnServerEvent:Connect(function()
    
    CarClone.Parent = game.Workspace
    
    CarClone:MakeJoints()
    
    CarClone:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame + Vector3.new(0,10,15))
    
    end)
    
    end)

2 comments

0

so whats the issue?

0

The model i try to spawn near by my RootPart is not spawning there

1 answer

✓ Accepted answer

Hey! I'm BlackOrange3343 and I'll be helping you today.

To be honest, reading this code makes my head hurt. So I'm going to keep it simple.

If I recall, you can't add Vector3 values to CFrame values. (I'm really not sure on this one)

But try: CarClone:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame * CFrame.new(0,10,15))

If it does start putting the car in a different position then re adjust the values within the parameters.

I'm not too sure about Vector3 and CFrames in terms of their relation ship. I believe you can subtract Position away from Cframe leaving it with only Orientation but I'm not entirely sure. I'm guessing you just want to move the car above the character so it doesn't spawn directly in the character.

Anyway I hope this helped!

Best of luck developer!

BlackOrange3343

PS: If it errors, comment.

This discussion is preserved as it was. New answers, comments, and votes are closed.