Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

2 comments

0

Local?

0

no

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)

2 comments

0

It's still taking damage to myself

0

but i appreciate the answer :)

This discussion is preserved as it was. New answers, comments, and votes are closed.