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

How to cframe a model , With A PrimaryPart?

local ScaryMan = workspace.Boss

local BossRootPart = ScaryMan:WaitForChild("HumanoidRootPart")

local DebrisFolder = workspace.DebrisFolder

local SFX = workspace.SFX

local function CubeExplosion()
local CubeSFX = SFX.CubeAttack
local CubeExlosion = Instance.new("Part")

CubeExlosion.Size = Vector3.new(12, 12, 12)
CubeExlosion.BrickColor = BrickColor.new("Hot pink")
CubeExlosion.Transparency = 0.3
CubeExlosion.Position = BossRootPart.Position
CubeExlosion.Parent = DebrisFolder
CubeExlosion.Anchored = true
CubeExlosion.CanCollide = false
CubeSFX:Play()
wait(5)
CubeExlosion:Destroy()
end

local function Teleport() -- Teleport FUnction
	local Pos1 = Vector3.new(-171.5, 14, 26.999)
	local Pos2 = Vector3.new(-171.5, 14, -49.001)
	local Pos3 = Vector3.new(-93.5, 14, -49.001)
	local Pos4 = Vector3.new(-93.5, 14, 26.999)

	local RandomMath = math.random(1,4)
	if RandomMath == 1 then
		BossRootPart.Position = Pos1
	elseif RandomMath == 2 then
		BossRootPart.Position = Pos2
	elseif RandomMath == 3 then
		BossRootPart.Position = Pos3
	elseif RandomMath == 4 then
		BossRootPart.Position = Pos4
	end
end

wait(10)
print("Wait Over")
CubeExplosion()
wait(3)
print("Teleporting")
Teleport()

I have searched around how to teleport a model but i did not really find something helpfull so i tried making my own script but IT only teleports the HumRootPart

1 answer

✓ Accepted answer

There's 3 ways to solve this. First of all, use CFrame, not Vector3. The reason why is because Vector3 will only teleport a part away, and because of that, it will potentially kill your character. CFrame takes that into account and can easily teleport players. The 3 ways are: SetPrimaryPartCFrame Just doing HumRootPart.CFrame or Model:MoveTo().

SetPrimaryPartCFrame (Recommend you do this as it keeps your orientation).

local model = ScaryMan

model:SetPrimaryPartCFrame(CFrame.new(-161, 0, -49)) --Set this as you want.

Model:MoveTo() (Only recommended if you don't want the orientation.)

local model = ScaryMan

model:MoveTo(Vector3.new(-161,0,-49)) --This takes a Vector3, not CFrame.

Setting the CFrame directly (This works but it sometimes doesn't work for me, so I go with the first option.)

local humRootPart = ScaryMan:WaitForChild("HumanoidRootPart")

humRootPart.CFrame = CFrame.new(-161, 0, -49)

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