Problem with touch verification

So I have a local script that lies in a tool

local player = game:GetService("Players").LocalPlayer
local tween = game:GetService("TweenService")
local debounce1 = true
local debounce2 = true

local function dynamiteTouched()
	if script.Parent:WaitForChild("DynamiteValue").Value ~= nil then
		script.Parent:WaitForChild("DynamiteValue").Value.Touched:Connect(function(hit)
			if hit.Name == "HitBox1Train" and debounce1 == true then
				wait(0.3)
				debounce1 = false
				
				local cloneText = player.PlayerGui.PowerUp.plusPower:Clone()
				cloneText.Parent = player.PlayerGui.PowerUp
				cloneText.Visible = true
				cloneText.Name = "plusPowerClone"
				cloneText.countText.Text = player.Data.PlusDamage.Value
				cloneText.Position = UDim2.new(math.random(100, 800)/1000, 0, math.random(200, 800)/1000, 0)				
				local targetSize = UDim2.new(0.093, 0, 0.181, 0)
				local tweenInfo = TweenInfo.new(0.3)
				
				local damageCount = player.PlayerGui.ShowStatsUnder.Damage
				local targetPosition1 = UDim2.new(0.4, 0, -0.02, 0)
				local targetPosition2 = UDim2.new(0.4, 0, 0, 0)
				local tweenInfo1 = TweenInfo.new(0.9)
				
				local tweenPosition1 = tween:Create(damageCount, tweenInfo1, {Position = targetPosition1})
				
				tweenPosition1:Play()
				
				
				local tweenSize = tween:Create(cloneText, tweenInfo, {Size = targetSize})
				tweenSize:Play()
				
				player.Data.DamageCount.Value = player.Data.DamageCount.Value + player.Data.PlusDamage.Value
				
				wait(0.1)
				
				local tweenPosition2 = tween:Create(damageCount, tweenInfo1, {Position = targetPosition2})
				tweenPosition2:Play()
				
				wait(0.8)
				
				cloneText:Destroy()
				debounce1 = true
			end
			
			if hit.Name == "Sand_1" and debounce2 == true then
				debounce2 = false
				hit:FindFirstChild("Current").Value -= player.Data.DamageCount.Value
				
				print("Sand1 Damage")
				
				hit:FindFirstChild("SurfaceGui").HpCount.Text = hit:FindFirstChild("Current").Value.. " / ".. hit:FindFirstChild("Max").Value
				
				local surfaceGui = hit:FindFirstChild("SurfaceGui")
				local greenGround = surfaceGui.GreenGround
				
				--local targetSize = UDim2.new(hit:FindFirstChild("Current").Value / hit:FindFirstChild("Max").Value, 0, 1, 0)
				--local targetPosition = UDim2.new(targetSize.X.Scale * -0.5, 0, 0, 0)
				
				greenGround:TweenSize(UDim2.new(hit:FindFirstChild("Current").Value / hit:FindFirstChild("Max").Value, 0, 1, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1)
				
				--hit:FindFirstChild("SurfaceGui").GreenGround:TweenSize(UDim2.new(hit:FindFirstChild("Current").Value / hit:FindFirstChild("Max").Value, 0, 0, 0), 1)	
				if hit:FindFirstChild("Current").Value <= 0 then
					wait(0.1)
					hit:Destroy()
					
					local vfx = workspace.Smoke_1:Clone()
					vfx.Parent = workspace.vfx
					vfx.Position = hit.Position
					vfx.Anchored = true
					vfx.ParticleEmitter:Emit()
					
					print("Sand1 was destroyig")
					
				end
				wait(1)
				debounce2 = true
			elseif hit.Name == "Sand_2" and debounce2 == true then
				debounce2 = false
				
				print("Sand2 Damage")
				
				
				hit:FindFirstChild("Current").Value -= player.Data.DamageCount.Value

				hit:FindFirstChild("SurfaceGui").HpCount.Text = hit:FindFirstChild("Current").Value.. " / ".. hit:FindFirstChild("Max").Value

				local surfaceGui = hit:FindFirstChild("SurfaceGui")
				local greenGround = surfaceGui.GreenGround

				greenGround:TweenSize(UDim2.new(hit:FindFirstChild("Current").Value / hit:FindFirstChild("Max").Value, 0, 1, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1)

				if hit:FindFirstChild("Current").Value <= 0 then
					wait(0.1)
					hit:Destroy()

					local vfx = workspace.Smoke_1:Clone()
					vfx.Parent = workspace.vfx
					vfx.Position = hit.Position
					vfx.Anchored = true
					vfx.ParticleEmitter:Emit()
					
					print("Sand2 was destroyig")
				end
				wait(1)
				debounce2 = true
			end
		end)
	end
end
script.Parent:WaitForChild("DynamiteValue"):GetPropertyChangedSignal("Value"):Connect(dynamiteTouched)

The problem is the line hit.Name == "Sand_1

You can see exactly what the problem is in the video here:

That is, as you see the first wall I destroy normally… But for some reason it is not removed, and further I can not pass.

This is one… and two is that the health of the second wall does not change.

I explain the second wall has an IntValue and it is 25. In the script, I say that Text = IntValue, but for some reason it does not do as it should.

As I understand the problem is that the check if I pass, and then all, then does not work. WHY?

2 Likes

Hmm, try printing debounce2 and the hit.Name out, so you can see if it even hits and can hit. Also I recommend you to make it all together instead of doing it manual and writing every wall on

1 Like