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

Cloning model into player glitching out, any help to fix it?

Asked by 4 years ago

Hello.

So I have this starship I made and I want to clone it into the player when they join, and weld it to them, so they are in the starship.

I have this code:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
    wait(5)
    print(player.Name .. " joined the game!")
    char = player.Character

    shipClone = script.Parent:Clone()
    shipClone.Parent = char

    shipClone.Anchored = true

    shipClone.Position = char:WaitForChild("HumanoidRootPart").Position
    char:WaitForChild("HumanoidRootPart").Position = shipClone.Seat.Position

    shipClone.WeldToPlayer.Part0 = char:WaitForChild("LowerTorso")
    shipClone.WeldToPlayer.Part1 = shipClone
end)

For some reason, whenever it happens the player is teleported to a new location, with only the parent part, everything else way off in the distance, and I am stuck in the air.

The error is probably very obvious, so sorry, I only got a couple hours of sleep last night. If you can figure out why it is doing this, please tell me.

Oh, and I am new to scripting, so there's that.

Props to you if you can help me out,

-ProqrammedGreen

1 answer

Log in to vote
1
Answered by 4 years ago

Set a primary part in the model and use Model:SetPrimaryPartCFrame, because otherwise setting the model's position will change only its root part's position.

    shipClone:SetPrimaryPartCFrame = char:WaitForChild("HumanoidRootPart").Position
    char:WaitForChild("HumanoidRootPart").Position = shipClone.Seat.Position

0
Thanks, got me onto the right track. Have some reputation points! proqrammed 285 — 4y
Ad

Answer this question