Help on my ";to" command

  1. What do you want to achieve?
    I am hoping to create an admin command, “;to”, that teleports you 5 studs in front of a player of your choice, and have you facing them (in front and face to face). The command would look like this: ";to (player-name).
    image

  2. What is the issue?
    I am unsure how to find where 5 studs in front of the player is along with rotating them according to the orientation of the player.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve searched google and youtube of tutorials on a “;to” command, but none show how to properly position the player to my liking.

--My full script
--// Chat Commands\\--
local cmds = {
	";kick",
	";to",
	";fly"
}

local admins = {
	"BoredMxghty",
	"TheIsolatedUser",
	"B1u6r",
	"Player1",
	"Player2"
}

game.Players.PlayerAdded:Connect(function(player)
	local character = player.Character or player.CharacterAdded:Wait()
	
	player.Chatted:Connect(function(message)
		for i, v in pairs(admins) do
			if player.Name == v then
				
				local loweredMsg = string.lower(message)
				local sep = string.split(loweredMsg, " ")
				
				if sep[1] == cmds[1] then
					
					local name = sep[2]
					
					for i, plr in ipairs(game.Players:GetDescendants()) do
						local foundName = string.lower(plr.Name)
						
						if foundName == name then
							local kicked = plr
							
							kicked:FindFirstChild("Kicks").Value += 1
							
							kicked:Kick("You were kicked")
						end
					end
				elseif sep[1] == cmds[2] then
					local name = sep[2]

					for i, plr in ipairs(game.Players:GetDescendants()) do
						local foundName = string.lower(plr.Name)
						
						if foundName == name then
							local to = plr.Character
							
							character.HumanoidRootPart.CFrame = CFrame.new(to.HumanoidRootPart.Position) * CFrame.new(5,0,0)
							character.HumanoidRootPart.CFrame = character.HumanoidRootPart.CFrame * CFrame.Angles(0,math.rad(180),0)
							
						end
					end
				elseif sep[1] == cmds[3] then
					local flown = sep[3]
					
					local character = player.Character or player.CharacterAdded:Wait()
					
					--character.Humanoid.StateType = Enum.HumanoidStateType.Flying
                    --WIP
				end
			end
		end
	end)
end)
--The area to focus on
elseif sep[1] == cmds[2] then
					local name = sep[2]

					for i, plr in ipairs(game.Players:GetDescendants()) do
						local foundName = string.lower(plr.Name)
						
						if foundName == name then
							local to = plr.Character
							
							character.HumanoidRootPart.CFrame = CFrame.new(to.HumanoidRootPart.Position) * CFrame.new(5,0,0)
							character.HumanoidRootPart.CFrame = character.HumanoidRootPart.CFrame * CFrame.Angles(0,math.rad(180),0)
							
						end
					end

(Please let me know if I should post this somewhere else or delete.)

Move them like so:

teleportingCharacter.HumRP.CFrame = teleportedToCharacter.HumRP.CFrame * CFrame.new(0,0,5) * CFrame.Angles(0,0,math.rad(180))

Easier version:

local offset = CFrame.new(0, 0, 5) -- Mess around with changing the X/Z position to 5 or by making the 5 negative
local rotation = CFrame.Angles(0,0,math.rad(180)) -- Mess around with the X/Z (I doubt its Y for either)
teleportingCharacter.HumRP.CFrame = teleportedToCharacter.HumRP.CFrame * offset  * rotation

Try making the offse

1 Like

Thank you, I will be testing this now. Will be back with results.

Works well! Had to tweak a bit, but all is well!

(Had to switch to a negative 5, for that is whatmoved them in front of the player. Also has to move the rotation to the y axis, for the z axis flipped them up-side-down.)

Try multiplying the first dummies lookvector by the amount of studs you want to have it in front of.

Player2.Character.HumanoidRootPart.CFrame = Player1.Character.HumanoidRootPart.CFrame + Player1.Character.HumanoidRootPart.CFrame.LookVector * 5

It worked for me.

CharacterFrom:PivotTo(CharacterTo.PrimaryPart.CFrame)

This is what you should be using, “CharacterFrom” being the teleporting character and “CharacterTo” being the character teleported to.