Hit Damage Problem

hello guys me again and now i need your help again plss help me to my problem the hit the does damage run so many time and it does damage more than the damage value plss help me

image

-- normal script
local item = script.Parent:WaitForChild("Items")
local remote = item:WaitForChild("Remote")
local fireball = item:WaitForChild("FireBall")
local damage = item:WaitForChild("Damage")

local TS = game:GetService("TweenService")

local damagedebounce = false

remote.OnServerEvent:Connect(function(player , mouse , human , barrel)
	warn(player.Name)
	local newFireBall = fireball:Clone()
	newFireBall.Transparency = 0
	newFireBall.CanCollide = false
	newFireBall.Fire.Enabled = true
	newFireBall.Parent = workspace
	newFireBall.CFrame = barrel.CFrame * CFrame.new(0,0,0)
	
	local BV = Instance.new("BodyVelocity")
	BV.Parent = newFireBall
	BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	BV.Velocity = mouse.LookVector * 50
	
	local Attact1anim = item:WaitForChild("Attact1")
	
	local attact1 = human:LoadAnimation(Attact1anim)
	attact1:Play()
	
	newFireBall.Touched:Connect(function(hit)
		
		if hit.Parent:FindFirstChild("Humanoid") and damagedebounce == false and hit.Parent.Name ~= player.Name then
			damagedebounce = true
			
			local Explosion = Instance.new("Part")
			Explosion.Name = "Explosion"
			Explosion.Anchored = true
			Explosion.BrickColor = BrickColor.Red()
			Explosion.CanCollide = false
			Explosion.Shape = "Ball"
			Explosion.Material = Enum.Material.ForceField
			Explosion.Size = Vector3.new(0,0,0)
			Explosion.Parent = workspace
			Explosion.CFrame = newFireBall.CFrame * CFrame.new(0,1,0)
			
			local goal = {}
			goal.Size = Vector3.new(20,20,20)			
			local info = TweenInfo.new(1)			
			local tween = TS:Create(Explosion , info , goal)			
			tween:Play()
			
			Explosion.Touched:Connect(function(obj)
				local exDV = false
				local dmdv = false
				
				local newDV = false
				
				local enemyhuman = obj.Parent:FindFirstChild("Humanoid")
				local enemyroot = obj.Parent:FindFirstChild("HumanoidRootPart")
				
				
				if enemyhuman and enemyroot and obj.Parent.Name ~= player.Name then
					if newDV == false then
						newDV = true
						newFireBall:Destroy()
						enemyhuman:TakeDamage(damage.Value)
						wait(1)
						Explosion:Destroy()
						newDV = false
					end
					
				end
				--[[
				if exDV == false and obj.Parent.Name ~= player.Name and enemyhuman and obj.Name == "HumanoidRootPart" and enemyroot and obj.Parent.Name == obj.Parent.Name then
					exDV = true
					newFireBall:Destroy()
					if dmdv == false and enemyhuman and enemyroot then
						dmdv = true
						enemyhuman:TakeDamage(damage.Value)
						wait(1)
						dmdv = false
					end
					wait(1)
					Explosion:Destroy()
					exDV = false					
				else
					print("no obj")
				end]]--
			end)
			wait(1)
			damagedebounce = false
		end
	end)
	game:GetService("Debris"):AddItem(newFireBall , 2)
end)


-- local script

local tool = script.Parent
local item = script.Parent:WaitForChild("Items")
local remote = item:WaitForChild("Remote")

local barrel = script.Parent.Barrel
local debounce = false

local AddHealth = item:WaitForChild("AddHealth").Value
local AddSpeed = item:WaitForChild("AddSpeed").Value
local AddMax = item:WaitForChild("AddMaxHealth").Value

local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = player.Character or player.CharacterAdded:Wait()
local human = char:WaitForChild("Humanoid")
local mouse = player:GetMouse()

local realmaxhealth = human.MaxHealth
local realhealth = human.Health
local realspeed = human.WalkSpeed

tool.Equipped:Connect(function()
	human.MaxHealth = human.MaxHealth + AddMax
	human.Health = human.Health + AddHealth
	human.WalkSpeed = human.WalkSpeed + AddSpeed
end)

tool.Unequipped:Connect(function()
	human.MaxHealth = human.MaxHealth - AddMax
	human.Health = human.Health - AddHealth
	human.WalkSpeed = human.WalkSpeed - AddSpeed
end)

tool.Activated:Connect(function()
	if debounce == false then
		debounce = true
		remote:FireServer(mouse.hit , human , barrel)
		wait(1)
		debounce = false
	end
end)

the damage is only 5 but it does more than 1000 damage and i already spent 2 hours to fix i i cant plss help me :frowning:

You’ve posted a lot of code. Next time, try posting less to attract more people to help. If they ask to show more code, then you could.


Your not disconnecting the .Touched function. Everytime you click, your multiplying the damage. Instead, try grouping all of your code inside the .Touched, and put it inside of a function to disconnect, like this;

local myTouching = partTouched.Touched:Connect(OnTouched)

function OnTouched()
	-- Put all code that was inside the old .Touched.
	
	-- At the end...
	myTouching:Disconnect()
end

Your also calling a .Touched event inside a .Touched event. So you may have to do what I said twice or try optimizing your code a little bit.

3 Likes

how can i make this when im using the another method of function?

i think its like this

 local connect
 connect = script.Parent.Touched:Connect(function()
        connect:Disconnect()
 end)
1 Like

so i see the local connect is = to nil and i add the connect to the function ?

yes

1 Like

thank you so much its work and also fastkingyaya is also work but i’m not familiar using the function he gave thank you all

1 Like