i made a script where it spawns an object depending where the mouse is placed but when i added this damage script with together the spawn script, everything failed. When i spawn it in, it would work the first time the object spawn in but after a few seconds, the tween would loop again and it wouldn't return to the size before it was tween.

if you need to know any variables just ask.

Script:

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E and debounce then
		debounce = true
		
		clone.Parent = game.Workspace
		
		local mousePos = mouse.Hit.p	
		clone.Position = mousePos
		
		local Tween = TS:Create(clone,TI,PP)
		Tween:Play()
	
clone.Touched:Connect(function(h)
	if h.Parent:FindFirstChild("Humanoid") and h.Parent.Name ~= player.Name then
		print('hello')
		
		local enemyhumanoid = h.Parent.Humanoid
		enemyhumanoid:TakeDamage(15)
		
		clone.Size = Vector3.new(5,4,5)
		
		wait(1.5)
		clone.Parent = nil
		
		debounce = false
	      end
       end)
	end
end)

3 comments

1

Posting the scripts for the properties and tweening info would be a good choice. It can also lead to your answer being solved.

0

The problem probably lies in where your debounces are placed. For one, you checked if Debounce was true, and then set it to true, instead of false. Also, the debounce is being set before the Humanoid is checked on the hit event. That means that if the player presses the button more than once, its going to fire more than once (because of the lack of debounce) and also if the player touches

0

something more than once, the same issue is going to occur.