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

Why isn't HumanoidRootPart not teleporting?

Hello there, So I'm trying to teleport a player to a certain part using HumanoidRootPart after the timer is over. But it doesn't seem to work.

Here is the script:

local roundLength = 5
local intermissionLength = 5
local InRound = game.ReplicatedStorage:WaitForChild("inRound")
local Status = game.ReplicatedStorage:WaitForChild("Status")
local LobbySpawn = game.Workspace.LobbySpawn
local GameAreaSpawn = game.Workspace.GameAreaSpawn

InRound.Changed:Connect(function()
	wait(1)
	if InRound.Value == true then
		for _, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			char.HumanoidRootPart.CFrame = GameAreaSpawn.CFrame
		end
	else
		for _, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
		end
	end
end)



local function roundTimer()
	while wait() do
		wait(4.5)
		for i = intermissionLength, 1, -1 do
			InRound.Value = false
			wait(1)
			Status.Value = "Next minigame in: ".. i ..""		
		end
		wait(4.5)
		for i = roundLength, 1, -1 do
			InRound.Value = true
			wait(1)
			Status.Value = "Time left: ".. i .." seconds!"
		end
	end
end
spawn (roundTimer)

I did a research and tried to Google it but nothing seems to work. Thank you!

6 comments

0

It works

0

Use Model:MoveTo() or Model:SetPrimaryPartCFrame(). I suggest you choose the latter (or second) since it tracks both your position and orientation.

0

@NoelGamer06 , doesn't seem to work for me though.

0

@Dovydas1118 , so I tried to do it but it doesn't work could you maybe send me how you did it?

0

I'm almost certain it's because your script is unable to actually execute the signal. You should be using a coroutine instead of the spawn() function.

0

@DeceptiveCaster , I created the coroutine and now it works, thanks!

1 answer

When setting a CFrame value you need to set it to the "CFrame.new" data type. Example:

char.HumanoidRootPart.CFrame = CFrame.new()

CFrame accounts for both position and orientation, so when you set something else to a CFrame you need to account for this. If I were you I would do

``char.HumanoidRootPart.CFrame = CFrame.new(GameAreaSpawn.Position)

That will set only the position of the player if you wanted to also set their orientation just add another value to the argument section.

I'm pretty new to Lua scripting, but as far as I can tell that's your problem, but I may have missed something.

2 comments

0

You don't need to use CFrame.new() to set CFrame

0

My bad, yea thats my fault, disregard my answer above.

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