#Touch event fire once

21 messages · Page 1 of 1 (latest)

tired surge
#

debounce

onyx coyote
tired surge
#

example

#

dont think it will work in your case tho wait

#

maybe make the db be an array

#

to be per person

#

if thats what u want

balmy granite
#

set a variable to the false boolean before writing the code. Inside the code check if the variable is false and if it is turn it true and then run your script, after script ends turn the variable back to false

onyx coyote
#

ill show u guys what the problem is

balmy granite
#

Yes

#

Thats why add a debounce

onyx coyote
#
local eggFolder = game.Workspace.spawnedEggs
local db = false

eggFolder.ChildAdded:Connect(function() 

    for _, v in pairs(eggFolder:GetChildren()) do

        if v.Name == "Egg" then
            
            v.Touched:Connect(function(hit)
                
                if hit.Parent == workspace then return end
                
                local hum = hit.Parent:WaitForChild("Humanoid")
                
                if hum and not db then
                    db = true
                    v:Destroy()
                    game.Players:FindFirstChild(hit.Parent.Name).leaderstats.Eggs.Value += 1
                    db = false
                end

            end)


        end

    end
    
end)

did i do it wrong

balmy granite
#

and then paste your for loop inside the if loop

onyx coyote
#

but hum isnt defined then

balmy granite
#

Use touched event

#

not child added then

onyx coyote
#

alr