#Script executes twice

1 messages · Page 1 of 1 (latest)

honest sundial
#

I tried debounce too, but still executes twice. It gets 3, while it should have gotten 2.

if itemToAppear:HasTag("Upgrader") then
                    childTransparency = 0.5
                    local upgrader = itemToAppear
                    upgrader.Touched:Connect(function(toucher)
                        if toucher:HasTag("Drop") then
                            upgrader.CanTouch = false
                            local getCost = toucher:GetAttribute("Cost") + 1
                            toucher:SetAttribute("Cost", getCost)
                            toucher.BillboardGui.TextLabel.Text += tostring(getCost)
                            task.wait(1)
                            upgrader.CanTouch = true
                        end
                    end)
glacial ginkgo
#

your not even checking if the debounce is true

honest sundial
glacial ginkgo
#

oh lol

#

just use a debounce

signal dew
#

it would be better to use a variable debounce here

glacial ginkgo
#

yeah

signal dew
#

changing the touchable might take a small amount of time to take effect

#

a variable change is pretty much instant

honest sundial
# signal dew it would be better to use a variable debounce here

Yes still the same

if itemToAppear:HasTag("Upgrader") then 
                    childTransparency = 0.5
                    local upgrader = itemToAppear
                    upgrader.Touched:Connect(function(toucher)
                        if toucher:HasTag("Drop") then
                            if debounce1 == true then return end
                            debounce1 = true
                            local getCost = toucher:GetAttribute("Cost") + 1
                            toucher:SetAttribute("Cost", getCost)
                            toucher.BillboardGui.TextLabel.Text += tostring(getCost)
                            task.wait(1)
                            debounce1 = false
                        end
                    end)
signal dew
#

hm. what kind of script is this running in?

honest sundial
#

Server

signal dew
#

also, could we see the code around this if statement?

signal dew
#

cool, ill have a look now.

honest sundial
signal dew
#

you made it work?

honest sundial
#

Yes

signal dew
#

ah ok

#

may i know how?

honest sundial
#

Actually it was executing once

#

the getCost variable is 2, so the "Cost" attribute gets 2, but the text gets 3 because there is a 1 += 2