-
I want two rigs/characters to swap positions when a function is invoked
-
The code works fine, but whenever I reset and do it, instead of teleporting to the other rig’s position, I teleport to where I died.
-
Ive recoded this same code 3-4 times, and tried every (?) method of moving the character but the same issue arrises.
function module.Swap(player, keystroke)
if FuncsMDL.manacheck(player, 20) == false then return end
local character = player.Character
local RootPart = character.HumanoidRootPart
local Hum = character.Humanoid
local animator = Hum:WaitForChild("Animator")
local track = Hum.Animator:LoadAnimation(game.ReplicatedStorage.Animations.Magic.Snap)
track:Play()
task.spawn(function()
wait(0.3)
FuncsMDL.sound(game.ReplicatedStorage.FX.Sounds.Magic.FingerSnap, character.RightHand, 2)
end)
miscscreen:FireClient(player, "GETCAMERADIR")
miscscreen.OnServerEvent:Connect(function(player2, pos, dir)
if player2 ~= player then return end
local params = RaycastParams.new()
params.FilterDescendantsInstances = {character:GetChildren()}
params.FilterType = Enum.RaycastFilterType.Exclude
params.IgnoreWater = true
local raycast1 = workspace:Raycast(pos, dir * 500, params)
if raycast1.Instance then
local function createpart(hitted)
local part = Instance.new("Part")
part.Transparency = 0.5
part.CanQuery = false
part.CanCollide = false
part.Anchored = true
part.Parent = workspace
part.CFrame = hitted.CFrame
part.Size = hitted.Size
part.Color = Color3.new(1, 0, 0)
part.Material = Enum.Material.Neon
game.Debris:AddItem(part, 10)
return part
end
local hit = raycast1.Instance
if hit.Anchored == false then
if hit.Parent:IsA("Model") and hit.Parent.PrimaryPart ~= nil then
hit = hit.Parent.PrimaryPart
end
local enemypart = createpart(hit)
local playerpart = createpart(RootPart)
character:SetPrimaryPartCFrame(enemypart.CFrame)
hit.CFrame = playerpart.CFrame
end
end
end)
end
Before dying:
after dying
ive geniuenly tried every method i could come up with to fix this, its been plaguing my game for a few months now because I really want this ability to work