I made a working teleport command and currently it teleports you +3 away from the player on the X axis. But I want it to teleport the player right in front of the player who called the command. Like this:
local function findplayer(name)
--sorry for making it so long -------------------------
print("started process")
for i,v in pairs(game.Players:GetPlayers()) do
print("looping")
local name1 = string.lower(v.Name)
if string.sub(name1, 1, string.len(name)) == name then
print("found player")
return v
end
end
end
local function handler(message, plr)
print("function")
local prefix = ":"
local spacer = " "
local lower = string.lower(message)
local args = string.split(lower, spacer)
local cmd = string.split(args[1], prefix)
if cmd[2] == "tp" then
print("tp")
if args[2] and args[3] then
print("cmd aloud")
local char3 = game.Workspace[(findplayer(args[2])).Name]
print(char3)
local char4 = game.Workspace[(findplayer(args[3])).Name]
print(char4)
char3.HumanoidRootPart.CFrame = CFrame.new(char4.HumanoidRootPart.CFrame.X-3,char4.HumanoidRootPart.CFrame.Y,char4.HumanoidRootPart.CFrame.Z+3)
print("done")
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(message)
print("chatted")
handler(message, plr)
end)
end)
game.ReplicatedStorage.Get.OnServerEvent:Connect(function(plr, message) -- receives here
print("received")
handler(message, plr)
end)
By face to face, I mean exactly like the picture, not just looking at each other.
Thank you in advance!
Humm, you just want to teleport player to infront player, that script should work. What was the direction of the person get teleport? Can you show me a picture?
I’ve did a research and I found a post that should help you with, you can make Target is the HumanoidRootPart of player who teleported and the character is the person who get teleported.The post that I recommended to read is here.
EDIT : Take the second answer, that should solve your problem.
Right, so in your image you want both of them facing eachother, thats what that will do.
Here, I will clear it up:
Get issuers CFrame Rotation
Do a difference of (0,180,0) to make it so that the returned CFrame will cause the rotation of the player to be looking at the issuer.
Apply the CFrame rotation to the person being teleported.
EDIT:
By difference I mean a calculation which will return the desired rotation, but you can just take the above reply
Oh, you are trying to simply get a player to TP infront of another player and face them?
Okay, one moment
EDIT:
Looked at some other posts, the easiest way to offset a CFrame set is like this:
local offset = Vector3.new() -- you might want to do Vector3.new(-3,0,3) based off of what I saw in script
char3.HumanoidRootPart.CFrame = char4.HumanoidRootPart.CFrame*CFrame.new(offset)
You said its teleporting to a random location, right? Could you try this instead?
Or did you mean rotation?
I’m confused on what you are really trying to do, but looking at your code, this should hopefully work.
Hello! Thanks again for your reply. I tried this and it TP’s the player beside it in front of it or behind it depending on where your standing. I’m looking for it to always be in front.
After fooling around with it for an hour or 2 I finally found something I’m happy with. It’s not exactly what I wanted, but it’s good enough. This one teleports you in front of the player, but not face to face. Here is what I used:
Update #2
Turns out the last one didn’t work. It only worked in one position.
So kept trying and trying. And I figured it out, this is what it looks like: