I’m trying to make an ability in my game where the player using it swaps positions with the nearest player, but it won’t teleport. It does grab the positions of the players, however it just won’t swap them, here’s the script, if you have anything to help please let me know:
local plrs = game:GetService("Players")
local maxd = 10
game.ReplicatedStorage.AbilityEvents.Biar.OnServerEvent:Connect(function(plr)
local hrp = plr.Character.HumanoidRootPart
local nearestplr, nearestdistance
for _, player in pairs(plrs:GetPlayers()) do
if player.Name ~= plr.Name then
local vchar = player.Character
local distance = player:DistanceFromCharacter(hrp.Position)
if not vchar or distance > maxd or (nearestdistance and distance >= nearestdistance) then
continue
end
nearestdistance = distance
nearestplr = player
local hrppos = hrp.Position
local charpos = nearestplr.Character.HumanoidRootPart.Position
hrppos = charpos
charpos = hrppos
end
end
end)