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

how do i make the player jump backwards when touching an object?

Asked by 2 years ago

i am try to make make it so when a player is touching a certain object, the player jumps backwards but the script I made is only making the player jump.

damagePlane = script.Parent

function damage(hit)
    local partParent = hit.Parent
    local humanoid = partParent:FindFirstChild("Humanoid")
    local player = game:GetService("Players"):GetPlayerFromCharacter(partParent)
    local character = player.Character
    local rootPart = player.Character:FindFirstChild("HumanoidRootPart")
    local direction = rootPart.CFrame + rootPart.CFrame.LookVector
    if player then
        humanoid.Jump = true
        player:Move(-direction, false)
    end
end

damagePlane.Touched:Connect(damage)
0
It’s humanoid move, not player move T3_MasterGamer 2189 — 2y
0
when I changed that i got this error message Workspace.(model that the damage plane is in).damagePlane.damage:12: attempt to perform arithmetic (unm) on CFrame wackypug09 2 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

You mean knockback right?

script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
        if not humanoid.Parent.Torso:FindFirstChild("VectorForce") then
            local VectorForce = Instance.new("VectorForce")
            local Attachment = Instance.new("Attachment")

            VectorForce.Parent = humanoid.Parent.Torso
            Attachment.Parent = humanoid.Parent.Torso
            VectorForce.Force = Vector3.new(0,300,6000) ---You might need to change this
            VectorForce.Attachment0 = Attachment
            VectorForce.ApplyAtCenterOfMass = true
            humanoid.Jump = true
            game:GetService("Debris"):AddItem(VectorForce,0.5)
            game:GetService("Debris"):AddItem(Attachment,0.5)
        end
    end
end)
Ad

Answer this question