local player = game:GetService("Players").LocalPlayer
local tween = game:GetService("TweenService")
local debounce = 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" then
wait(0.3)
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()
end
if hit.Name == "Sand_1" and debounce == true then
debounce = false
print("Hit")
print(debounce)
debounce = true
end
end)
end
end
script.Parent:WaitForChild("DynamiteValue"):GetPropertyChangedSignal("Value"):Connect(dynamiteTouched)
So I have a script that checks which desk I touched when I throw dynamite. The problem is this. When it touches a part, it prints several times. But I need to print only once. What kind of check should I put on it?
watch. This is the value, this is roughly the name of the subject. I’m checking to see if THIS item has touched the right thing. Like if dynamite was touched, then call the function, and if a hand was touched, then don’t call it.
if hit.Name == "Sand_1" and debounce == true then
debounce = false
print("Hit")
print(debounce)
debounce = true
end
You check if hitname is sand_1, and if debounce. Then you set debounce to false, but you immediately set it back to true. The goal of debounce is to add some time in between, so add a wait in between print(“Hit”) and print(debounce). That’ll ensure it doesn’t trigger multiple times.