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

Why wont the player be teleported, yet it goes to the next line?

So, I have a system where when a player is killed, and they are hostile, they go to jail. However, it wont teleport them to the jail.

function charAdd()
	print("respawn")
	local char = script.Parent.Parent.Character
	if script.Parent.Parent.TeamColor == BrickColor.new("Bright orange") then
		script.Parent.Parent.Neutral = false
		char:MoveTo(game.Workspace.PrisonBlock.Position + Vector3.new(0,1,0))
		print("waiting")
		wait(script.Parent.Parent.leaderstats.JailTime.Value)
		script.Parent.Parent.TeamColor = BrickColor.new("White")
		script.Parent.Parent.Neutral = true
		print("out of jail")
		script.Parent.Parent.leaderstats.JailTime.Value = 0
		char.Humanoid.Health = 0
	end
	
end
script.Parent.Parent.CharacterAdded:Connect(charAdd)

1 answer

✓ Accepted answer

I've never seen anyone use MoveTo to teleport a player. Use CFrame though.

function charAdd()
    print("respawn")
    local char = script.Parent.Parent.Character
    if script.Parent.Parent.TeamColor == BrickColor.new("Bright orange") then
        script.Parent.Parent.Neutral = false
        char:WaitForChild("HumanoidRootPart").CFrame = game.Workspace.PrisonBlock.CFrame
        print("waiting")
        wait(script.Parent.Parent.leaderstats.JailTime.Value)
        script.Parent.Parent.TeamColor = BrickColor.new("White")
        script.Parent.Parent.Neutral = true
        print("out of jail")
        script.Parent.Parent.leaderstats.JailTime.Value = 0
        char.Humanoid.Health = 0
    end

end
script.Parent.Parent.CharacterAdded:Connect(charAdd)

2 comments

0

You can use MoveTo() as well.

1

CFrame is just genuinely better I guess

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