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

How to launch/fling something in the direction the player is looking?

Asked by 3 years ago
Edited 3 years ago

The something I want to push is another player but, I want to make it the direction they are being pushed from is where the other player is looking. The main issue that I am having is the player is only being flung in a single direction and not relative to where the other player is looking. Hopefully that made sense, torso = HumanoidRootPart --torso for testing purposes

game.ReplicatedStorage.RemoteEventhammer.OnServerEvent:Connect(function(player,cframe,toPush)
    local sword = game.ServerStorage:WaitForChild("hammer")
    local character = player.Character
    local arm = player.Character:WaitForChild("Torso")
    local newsword = sword:Clone()
    local launch = Instance.new("BodyVelocity")
    local playerRoot = player.Character:FindFirstChild("HumanoidRootPart")

    newsword.CFrame = character.HumanoidRootPart.CFrame
    newsword.Parent = workspace
    local Y = Instance.new("Weld")
    Y.Part0 = arm
    Y.Part1 = newsword
    Y.Parent = Y.Part0

    local touchconn

    touchconn = newsword.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") then
            if hit.Parent.Name ~= player.Name then
                hit.Parent.Humanoid.PlatformStand = true
                if(playerRoot and not playerRoot:FindFirstChild("launch") and hit.Parent.Torso and not hit.Parent.Torso:FindFirstChild("launch") and (playerRoot.Position - hit.Parent.Torso.Position).magnitude <= 10) then
                    launch.MaxForce = Vector3.new(1000, 1000, 1000)
                    launch.Velocity = (-hit.Parent.Torso.CFrame.lookVector) * 110
                    launch.Parent = hit.Parent.Torso 
                    hit.Parent.Humanoid:TakeDamage(15)
                    wait()
                    if touchconn ~= nil then touchconn:Disconnect() end
                    newsword:Destroy()
                    wait(2)
                    hit.Parent.Humanoid.PlatformStand = false
                    launch:Destroy()
                end
            end
        end
    end)
    wait(1)
    if touchconn ~= nil then touchconn:Disconnect() end
    newsword:Destroy()
end)

Answer this question