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

Make my script only deal damage when keycode C is clicked?

Asked by 2 years ago

Hello! Im trying to make a dropkick script, ive already got everything set except i encountered one major problem. My intention was to have the player deal damage to an enemy when they click the keycode C but the players legs constantly deal damage, i dont know what to do please help

--Made By 123Marooxd123
local lleg = script.Parent:FindFirstChild("Left Leg")
local rleg = script.Parent:FindFirstChild("Right Leg")

local UIS = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local DropAnim= Instance.new("Animation")
DropAnim.AnimationId = "rbxassetid://9642052968"

local dmg = false
local CanDropkick = false
local Keybind = Enum.KeyCode.E
local LeftLeg = game.Players.LocalPlayer.Character["Left Leg"]
local RightLeg = game.Players.LocalPlayer.Character["Right Leg"]

local topspeed = 25
character.Humanoid.Running:Connect(function(speed)
    if speed > topspeed then
        CanDropkick = true
        dmg = true
    else if speed < topspeed then
            CanDropkick = false
            dmg = false
        end
    end
end)



function dmg(hit) --- this is the function that lets the player deal damage with their legs
    if hit.Parent ~= nil then
        local hum = hit.Parent:findFirstChild("Humanoid")
        if hum ~= nil then
            hum.Health = hum.Health -10
        end
    end
end

lleg.Touched:connect(dmg)
rleg.Touched:connect(dmg)

UIS.InputBegan:Connect(function(input,gameprocessed)
    if gameprocessed then return end
    if not CanDropkick then return end
    if not dmg then return end
    if input.KeyCode == Keybind then
        CanDropkick = false
        dmg = false





        local playAnim = character.Humanoid:LoadAnimation(DropAnim)

        playAnim:Play()
    local drop = Instance.new("BodyVelocity")
    drop.MaxForce = Vector3.new (1,0,1) *30000
    drop.Velocity = character.HumanoidRootPart.CFrame.lookVector * 85
    drop.Parent = character.HumanoidRootPart

        for count = 1, 8 do
    wait(0.13)
    drop.Velocity*= 0.5
        end

    playAnim:Stop()
    drop:Destroy()
        CanDropkick = true
        dmg = true
        end
    end)

1 answer

Log in to vote
0
Answered by 2 years ago
function dmg(hit) --- this is the function that lets the player deal damage with their legs
if not CanDropkick then return end
    if hit.Parent ~= nil then
        local hum = hit.Parent:findFirstChild("Humanoid")
        if hum ~= nil then
            hum.Health = hum.Health -10
        end
    end
end

Ad

Answer this question