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

My Punch-script is not making any damage and it's damaging myself?[STILL ACTIVE AFTER I UNEQUIP IT]

Asked by 4 years ago
Edited 4 years ago

To Expand, i created a punch tool. When you activate the tool, it fires an animation and does some damage.

Either it's not damaging the dummies, instead it damages me, it's still active, even after i unequip it.

I've been constantly working on this 24/7 and then i found out i could get some help on this site. not only for a good feel, but for future reference.

Local Script:

local Animation = script.Animation
local Replicated = game:GetService("ReplicatedStorage")
local RemoteEvent = Replicated.Remotes.Punch

local Debounce = false

wait(2)

local Humanoid = game.Players.LocalPlayer.Character.Humanoid

script.Parent.Activated:Connect(function()
    if not Debounce then
        Debounce = true

    local AnimationTrack = Humanoid:LoadAnimation(Animation)
    RemoteEvent:FireServer()
    wait(2)
    Debounce = false 
    end
end)

Server Script:

local Tools = game:GetService("ReplicatedStorage"):WaitForChild("Tools")
local RemoteEvent = game:GetService("ReplicatedStorage").Remotes.Punch
local Animation = Tools.SuperPunch.PunchConnecter.Animation

wait(1)

RemoteEvent.OnServerEvent:Connect(function(player)
    local Hum = player.Character.Humanoid
    local AnimationTrack = Hum:LoadAnimation(Animation)
    AnimationTrack:Play()

    if AnimationTrack.IsPlaying then
        local LeftArm = player.Character["RightHand"]

        LeftArm.Touched:Connect(function(hit)
            if hit.Parent:FindFirstChild("Humanoid") then

                    Hum:TakeDamage(20)
                    Hum.Sit = true          
    end
    end)
        end
        end)

2 answers

Log in to vote
0
Answered by 4 years ago

I personally prefer handling it all on a single script inside the tool

--Script
local tool = script.Parent;
local Animation = game.ReplicatedStorage:WaitForChild("Tools"):WaitForChild("SuperPunch"):WaitForChild("PunchConnecter"):WaitForChild("Animation")

local char
local humanoid = char:WaitForChild("Humanoid")
local RArm

local canAttack = true
local attacking = false 
local equipped = false

tool.Equipped:Connect(function()
    equipped = true
    RArm =  = char:WaitForChild("RightHand")
    char = tool.Parent
end)

tool.Unequipped:Connect(function()
    equipped = false
    attacking = false
end)

tool.Activated:Connect(function()
    if canAttack then
        canAttack = false
        attacking = true
        local AnimationTrack = Humanoid:LoadAnimation(Animation)
        AnimationTrack:Play()
        RArm.Touched:Connect(function(hit)
            local hum = hit.Parent:FindFirstChild("Humanoid")
            if hum and hit.Parent ~= char and equipped and attacking then
                hum:TakeDamage(20)
                hum.Sit = true
            end
        end)
        wait(1)
        canAttack = true
        attacking = false
    end
end)
0
Local? maxpax2009 340 — 4y
0
no Utter_Incompetence 856 — 4y
Ad
Log in to vote
0
Answered by
iuclds 720 Moderation Voter
4 years ago

You have to ignore the player on server

local Tools = game:GetService("ReplicatedStorage"):WaitForChild("Tools")
local RemoteEvent = game:GetService("ReplicatedStorage").Remotes.Punch
local Animation = Tools.SuperPunch.PunchConnecter.Animation

wait(1)

RemoteEvent.OnServerEvent:Connect(function(player)
    local Hum = player.Character.Humanoid
    local AnimationTrack = Hum:LoadAnimation(Animation)
    AnimationTrack:Play()

    if AnimationTrack.IsPlaying then
        local LeftArm = player.Character["RightHand"]

        LeftArm.Touched:Connect(function(hit)
        if hit.Parent.Name == player.Name or hit.Parent.Parent.Name == player.Name then return end
            if hit.Parent:FindFirstChild("Humanoid") then

                    Hum:TakeDamage(20)
                    Hum.Sit = true          
    end
    end)
        end
        end)
0
It's still taking damage to myself maxpax2009 340 — 4y
0
but i appreciate the answer :) maxpax2009 340 — 4y

Answer this question