You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
function triggering once per body part touched
What is the issue? Include screenshots / videos if possible!
it triggers multiple times
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried debounce it didnt work
code:
for _, part in game.Workspace:GetChildren() do
if part.Name == "beam" then
print(beamnum)
beamnum = round(beamnum + 1)
beam = "beam"..beamnum
part.Name = beam
part:WaitForChild("hi").Touched:Connect(function(hit)
task.wait()
dskl = dskl + 1
print(dskl)
hinum = part.Name
kamehameha(hit, bonniecheck, freddycheck)
gold = round(gold + scott)
end)
part:WaitForChild("hi").TouchEnded:Connect(function(hit)
task.wait()
dskl = dskl + 1
hinum = part.Name
kamehameha(hit, freddycheck, bonniecheck)
gold = round(gold - scott)
end)
end
end
dski prints hundereds of times. the code used to work fine but now it doesn’t work for some reason.
this is the problem because dskl is printing a lot. I need the function to run everytime the player touches it because the kamehameha function adds 1 if a player part is touched.
for _, part in game.Workspace:GetChildren() do
if part.Name == "beam" then
local da = true
print(beamnum)
beamnum = round(beamnum + 1)
beam = "beam"..beamnum
part.Name = beam
part:WaitForChild("hi").Touched:Connect(function(hit)
if da == true then
da = false
task.wait()
dskl = dskl + 1
print(dskl)
hinum = part.Name
kamehameha(hit, bonniecheck, freddycheck)
gold = round(gold + scott)
end
end)
part:WaitForChild("hi").TouchEnded:Connect(function(hit)
if da == false then
da == true
task.wait()
dskl = dskl + 1
hinum = part.Name
kamehameha(hit, freddycheck, bonniecheck)
gold = round(gold - scott)
end
end)
end
end
but still it will fire multiple times because anything that touch it will fire it
So you will need somthing to detect if player touched it
Like the first poster mentioned, you need to add a debounce to prevent the code from running multiple times upon part touch. You can then add a task.wait(1) for the code to wait 1 second before setting debounce back to false to prevent the code firing multiple times when being touched.
Did you try the code I sent you?
Let me know how it works.
Try to not call the same connection on the same part, it can cause bugs and unintended results. Try to encapsulate the code in a single function if you are referring to the same object.
yeah it didnt work. dont worry about fixing it I have a 500 line code that does what I want. I just wanted to optimize it but for some reason it works differently and Idk why