Script doing more damage than usual

Im trying to make a survival game, but the script is doing too much damage and firing when not clicking

Script doing more damage than usual, + damaging when not clicking

local Animator = workspace:FindFirstChild(script.Parent.Parent.Parent.Parent.Parent.Name):FindFirstChildOfClass("Humanoid"):FindFirstChildOfClass("Animator")
local Cooldown = script.Parent.Parent.Cooldown
local Animation  = script.Parent.Parent.Animation

script.Parent.MouseButton1Click:Connect(function() 
	if Animator then
		if Cooldown.Value == 0 then
			wait(0)
			Cooldown.Value = 2
			local anim = Animator:LoadAnimation(Animation)
			anim:Play()
			Animator.Parent.Parent:FindFirstChild("Hitboxes"):FindFirstChild("KickBox").Touched:Connect(function(otherPart: BasePart) 
				if script.Parent.Parent.Cooldown.Value == 0 then
					if otherPart.Parent:FindFirstChildOfClass("Humanoid") then
						otherPart.Parent:FindFirstChildOfClass("Humanoid"):TakeDamage(5)
					end	
				end
			end)		
			local anim = Animator:LoadAnimation(Animation)
			anim:Play()
	else
		print("Failed2")
	end
		
		
	else
		print("Failed")
	end
end)```

It does exact ammount of damage you specified.
You have no cooldown for firing

You never disconnect the touch function

Set the the touch connection to a variable, then when ever you deal damage, disconnect the connection

local touch
touch = part.touched:connect(function(part)
     touch:disconnect()
end)

2 Likes

Could one try using Once here

char

1 Like

I always forget once exists.

But yeah you could do once

1 Like

For example:

local touch
touch = part.touched:once(function(part)
     
end)

Code is just awful man wth

Also the hell even is that?

That legit looks like a code from this meme gifs :skull:

local Animator = workspace:FindFirstChild(script.Parent.Parent.Parent.Parent.Parent.Name):FindFirstChildOfClass("Humanoid"):FindFirstChildOfClass("Animator")
local Cooldown = script.Parent.Parent.Cooldown.Value::number
local Animation  = script.Parent.Parent.Animation::Animation

local anim = Animator:LoadAnimation(Animation)
local db = false

Animator.Parent.Parent:FindFirstChild("Hitboxes"):FindFirstChild("KickBox").Touched:Connect(function(otherPart: BasePart) 
	if not db then return end
	local hum:Humanoid? = otherPart.Parent:FindFirstChild("Humanoid")
	if not hum then return end
	hum:TakeDamage(5)
end)

script.Parent.MouseButton1Click:Connect(function():()
	if db then return end
	db = true
	anim:Play()
	task.wait(Cooldown)
	db = false
end)
2 Likes

Sorry for editing it after finding another problem with the code, but it doesnt fix the firing while not clicking problem

Just provide a solution and move on?

4 Likes

im not good at coding im sorry man

2 Likes

The thing you described is called solution farming, my friend.
What is the point of a solution without an actual explanation?
Also i did infact provide solution.
Besides, what is wrong with you disagreeing with straight-up facts?
That looks like a projection. Do you code that badly too?

This doesnt quite work

Also, please be a bit more respectful, thanks

1 Like

Nevermind ive fixed it myself using two scripts

wait(0.1)
local Animator = workspace:FindFirstChild(script.Parent.Parent.Parent.Parent.Parent.Name):FindFirstChildOfClass("Humanoid"):FindFirstChildOfClass("Animator")
local Cooldown = script.Parent.Parent.Cooldown
local Animation  = script.Parent.Parent.Animation

script.Parent.MouseButton1Click:Connect(function() 
	if Animator then
		if Cooldown.Value == 0 then
			wait(0)
			Cooldown.Value = 2
			local anim = Animator:LoadAnimation(Animation)
			anim:Play()
			local anim = Animator:LoadAnimation(Animation)
			anim:Play()
			Animator.Parent.Parent:FindFirstChild("KickboxScript").Enabled = true
			wait(0.1)
			Animator.Parent.Parent:FindFirstChild("KickboxScript").Enabled = false
	else
		print("Failed2")
	end
		
		
	else
		print("Failed")
	end
end)

touch = script.Parent:FindFirstChild("Hitboxes"):FindFirstChild("KickBox").Touched:Connect(function(otherPart: BasePart) 
	if otherPart.Parent:FindFirstChildOfClass("Humanoid") then
		if otherPart.Parent ~= script.Parent.Parent.Parent then
			otherPart.Parent:FindFirstChildOfClass("Humanoid"):TakeDamage(5)
			touch:Disconnect()
			script.Enabled = false
		end 
	end

end)

Use task.wait instead of wait. The better option.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.