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

Why my punch script keeps stacking damage until i touch another player, and how to stop it? [SOLVED]

Asked by 3 years ago
Edited 3 years ago

ServerScript

game.ReplicatedStorage.Attacks.Fisical.Punches.OnServerEvent:Connect(function(Player)
    local Character = Player.Character

    local Number = 1

    local Damage = Character.Strength

    local Debounce = false

    local Punch1 = Character.Humanoid.Attack1
    local Punch2 = Character.Humanoid.Attack2
    local Punch3 = Character.Humanoid.Attack3
    local Punch4 = Character.Humanoid.Attack4


    local animationTrack = Character.Humanoid:LoadAnimation(Punch1)
    local animationTrack2 = Character.Humanoid:LoadAnimation(Punch2)
    local animationTrack3 = Character.Humanoid:LoadAnimation(Punch3)
    local animationTrack4 = Character.Humanoid:LoadAnimation(Punch4)

    local HittedAnim = Instance.new("Animation")
    HittedAnim.AnimationId = "rbxassetid://6029310039"

    local HittedAnim2 = Instance.new("Animation")
    HittedAnim2.AnimationId = "rbxassetid://6029311348"

    if Character.Humanoid.MaxHealth == 2500 then
        if Number == 1 then
            animationTrack:Play()
            Character.Torso.Woosh:Play()
            Character["Left Leg"].Touched:Connect(function(Part)            
                local Humanoid = Part.Parent:FindFirstChild("Humanoid")                 
                if Humanoid and Humanoid.Parent.Name ~= Character.Name then
                    Humanoid:TakeDamage(Damage.Value / 20)
                    local animationTrack = Humanoid:LoadAnimation(HittedAnim)
                    local Hitted = Instance.new("Sound")
                    Hitted.SoundId = "rbxassetid://1693499499"
                    Hitted.Parent = Humanoid.Parent.Torso
                    Hitted.RollOffMaxDistance = 50
                    Hitted:Play()
                    animationTrack:Play()
                end
            end)
        end
    end
end)

local script

local UserInputService = game:GetService("UserInputService")

local Debounce = false
local Player = game.Players.LocalPlayer
local Char = Player.Character

UserInputService.InputBegan:Connect(function(Input, Typing)
    if not Typing then
        if Input.UserInputType == Enum.UserInputType.MouseButton1 and Debounce == false then
            Debounce = true
            game.ReplicatedStorage.Attacks.Fisical.Punches:FireServer()
            wait(.5)
            Debounce = false
        end
    end
end)

1 answer

Log in to vote
0
Answered by 3 years ago

I already solved it, i just needed to change some of the code and use ":Disconnect()"

Ad

Answer this question