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

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

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

✓ Accepted answer

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

1 comment

0

Thanks, got me onto the right track. Have some reputation points!

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