Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to switch position between 2 players?

Asked by 3 years ago

I would like to create a projectile that damages a person and switches the local players position with the player hit. I thought that I should get the players position and local players when they get hit, but I don't know how to record those values.

This is my current script:

local remote = game.ReplicatedStorage.BarrierTP
local debounce = false

remote.OnServerEvent:Connect(function(plr, mouseaim)
    local char = plr.Character
    local hum = char:WaitForChild("Humanoid")
    local hrp = char:WaitForChild("HumanoidRootPart")

    local projloc = game.ServerStorage.Classes.BarrierMaster.SwitchTP
    local barrierproj = projloc:Clone()
    barrierproj.Parent = workspace

    barrierproj.CFrame = hrp.CFrame * CFrame.new(0,3,0)
    barrierproj.CFrame = CFrame.new(barrierproj.Position, mouseaim)

    local tweenserv = game:GetService("TweenService")

    local TS = tweenserv:Create(barrierproj,TweenInfo.new(3),{CFrame = barrierproj.CFrame * CFrame.new(0,0,-300)})
    TS:Play()

    game.Debris:AddItem(barrierproj, 1)

    barrierproj.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name and debounce == false then
            debounce = true
            hit.Parent.Humanoid:TakeDamage(20)
            hrp.CFrame = hit.Parent.HumanoidRootPart.CFrame
            hit.Parent.HumanoidRootPart.CFrame = hrp.CFrame
                wait(1)
            debounce= false
            end
    end)



end)

Answer this question