I’m trying to make a tool that switches the places of 2 players - the one using the tool and the player their mouse is pointing at.
The one problem that I have is that the position of the players doesn’t change but it is doing something strange (as you can see in the video below)
This is the server side code that handles the teleportation
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemotesRE = ReplicatedStorage.Remotes.SwapRE
local MAX_DISTANCE = 50
RemotesRE.OnServerEvent:Connect(function(Player, Victim)
local char = Player.Character
local hum = char:FindFirstChild("Humanoid")
local hrp = char:FindFirstChild("HumanoidRootPart")
local Vchar = Victim.Character
local Vhum = Vchar:FindFirstChild("Humanoid")
local Vhrp = Vchar:FindFirstChild("HumanoidRootPart")
local PlayerPosition = hrp.Position
local VictimPosition = Vhrp.Position
if not (hrp and Vhrp and hum and Vhum) then return end
if hum.Health <= 0 or Vhum.Health <= 0 then return end
if (hrp.Position - Vhrp.Position).Magnitude <= MAX_DISTANCE then
local aux = char:GetPivot()
char:PivotTo(Vchar:GetPivot())
Vchar:PivotTo(aux)
print("Teleported")
end
end)
And also, another issue, with the logic that I’m trying to use now, wouldn’t the first player that is teleporting going inside the other player’s character and glitching, maybe even getting pushed? Cause I wouldn’t like that. I would’ve tested that already if the tp script even worked, but if that is really the case what should I do? I guess just turn the characters’ body parts cancollide property off and after the tp on. Let me know what you think