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

Trying to pull a player to another player, but it doesn't pull fast enough. Any tips?

Asked by 1 year ago

I'm making a script that pulls the nearest player. It runs properly, but the character moves over incredibly slowly unless they are in the air, which I have tried fixing by forcing them up with Velocity and by making them not collide, but the collision isn't working and the up velocity isn't something I liked. Could someone look my code over and give me some tips to make it work better?

RS.UtilEvents.PullRope.OnServerEvent:Connect(function(player, Password, Target)
    Target.Backpack.Stand.Value = 0
    local pos = player.Character.LowerTorso
    local bp = Instance.new("BodyPosition", Target.Character.HumanoidRootPart)
    local stringie = Instance.new("Part", player.Character.HumanoidRootPart)
    stringie.Shape = Enum.PartType.Block
    local Distance = (Target.Character.HumanoidRootPart.Position-player.Character.HumanoidRootPart.Position).Magnitude
    stringie.CFrame = CFrame.new(Target.Character.HumanoidRootPart.Position,player.Character.HumanoidRootPart.Position) * CFrame.new(0,0,-Distance/2)
    stringie.Size = Vector3.new(.3,.3,Distance)
    bp.Position = pos.Position
    stringie.Anchored = true
    stringie.CanCollide = false
    stringie.Material = Enum.Material.SmoothPlastic
    bp.D = 1000
    bp.MaxForce = Vector3.new(10000, 10000, 10000)
    bp.P = 10000 
    for i = 1,50 do
        wait(.1)
        bp.Position = pos.Position
        Distance = (Target.Character.HumanoidRootPart.Position-player.Character.HumanoidRootPart.Position).Magnitude
        stringie.CFrame = CFrame.new(Target.Character.HumanoidRootPart.Position,player.Character.HumanoidRootPart.Position) * CFrame.new(0,0,-Distance/2)
        stringie.Size = Vector3.new(.3,.3,Distance)
        if Distance < 3 then
            for _,v in pairs(Target.Character:GetChildren()) do
                if v:IsA("BasePart") then
                    v.CanCollide = true
                end
            end
        else
            for _,v in pairs(Target.Character:GetChildren()) do
                if v:IsA("BasePart") then
                    v.CanCollide = false
                end
            end
        end
        if i == 50 then
            for _,v in pairs(Target.Character:GetChildren()) do
                if v:IsA("BasePart") then
                    v.CanCollide = true
                end
            end
            Target.Backpack.Stand.Value = 1
            bp:Destroy()
            stringie:Destroy()
        end
    end
end)

Answer this question