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 5 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:

01local Players = game:GetService("Players")
02 
03Players.PlayerAdded:Connect(function(player)
04    wait(5)
05    print(player.Name .. " joined the game!")
06    char = player.Character
07 
08    shipClone = script.Parent:Clone()
09    shipClone.Parent = char
10 
11    shipClone.Anchored = true
12 
13    shipClone.Position = char:WaitForChild("HumanoidRootPart").Position
14    char:WaitForChild("HumanoidRootPart").Position = shipClone.Seat.Position
15 
16    shipClone.WeldToPlayer.Part0 = char:WaitForChild("LowerTorso")
17    shipClone.WeldToPlayer.Part1 = shipClone
18end)

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 5 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.

1shipClone:SetPrimaryPartCFrame = char:WaitForChild("HumanoidRootPart").Position
2char:WaitForChild("HumanoidRootPart").Position = shipClone.Seat.Position
0
Thanks, got me onto the right track. Have some reputation points! proqrammed 285 — 5y
Ad

Answer this question