So, I have this ball meging game. When two ball collide they both do the merging function, that’s why I have the debounce list so it doesn’t happend twice. But for some reason do the higher balls not work. With the lower balls I just delete one change the color and size, but with the better/higher ones. I delete both and make a new touched event. The problem is that 2 balls spawn.
local debounceList = {} -- if object data is logged inside of this, it can't be touched
local function ballFunction(ball, hit)
-- object wants to trigger touch with hit, is this allowed?
if debounceList[ball] or debounceList[hit] then
return false
end
-- both objects aren't reserved, we reserve them now and allow them to touch
debounceList[ball] = true
debounceList[hit] = true
task.delay(1, function() -- we unreserve them after 1 second to free up memory (by then hopefully the part is destroyed)
debounceList[ball] = nil
debounceList[hit] = nil
end)
return true -- yes, the parts can touch
end
Under here is the touched event.
newBall14.Touched:Connect(function(hit)
if hit:GetAttribute("Ball") == newBall14:GetAttribute("Ball") then
local canTouch = ballFunction(clone,hit)
if canTouch then
local shiny = 0
if hit:GetAttribute("Shiny") == true then
shiny += 1
end
if newBall14:GetAttribute("Shiny") == true then
shiny += 1
end
hit:Destroy()
merge(newBall14:GetAttribute("Ball") + 1, newBall14, shiny)
end
end
end)
ball 15 should spawn once, because of the debounce, but for some reason it still spawns twice.