Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Two scripts, a money script and GUI cloning script, only working once? ggargagrgrgrae

Asked by 5 years ago

The jist is that every time a player hit this block, one script increases a value in their leaderstats and the other clones and puts a GUI in their playergui (the gui just shows '+10', for the amnt gained)

However, it will only do this once. I am stumped. Why?

GUI cloning script:

local debounce = false



function getPlayer(humanoid) 

    local players = game.Players:children() 

for i = 1, #players do 

    if players[i].Character.Humanoid == humanoid then return players[i] end 

end 

    return nil 

end 



function onTouch(part) 



    local human = part.Parent:findFirstChild("Humanoid") 

if (human ~= nil) and debounce == false then



    debounce = true



    local player = getPlayer(human) 



    if (player == nil) then return end 



    user = game.Players:findFirstChild(human.Parent.Name)

    local gui= script.Parent.Plus:clone()
    gui.Parent = player.PlayerGui
    gui.Frame.Amount.Find.Disabled = false






    wait(2)

else

    wait(2)

    debounce = false

end

end





script.Parent.Touched:connect(onTouch) 

Cash adding script:

debounce = false

function onTouched(part)

    if debounce == false then

    local h = part.Parent:findFirstChild("Humanoid")


    if (h~=nil) then

        local thisplr = game.Players:findFirstChild(h.Parent.Name)

        if (thisplr~=nil) then

            local stats = thisplr:findFirstChild("leaderstats")

            if (stats~=nil) then

                debounce = true

                local cash = stats:findFirstChild("SpeedCoin")

                if (cash~=nil) then

                    cash.Value = cash.Value+ 10
                    wait(0.3)
                    debounce = false
                end
            end
        end
    end
    end
    end

script.Parent.Touched:connect(onTouched)
0
The title spam was because it would not let me post my question, saying it was not concise enough. Sorry Octocentillion 15 — 5y
0
It only adds cash once, or only shows the GUI once? DinozCreates 1070 — 5y
0
ggargagrgrgrae greatneil80 2647 — 5y
0
Both, Dinoz. Octocentillion 15 — 5y
View all comments (3 more)
0
Are they both server scripts? Why are they in seperate scripts? DinozCreates 1070 — 5y
0
they are both server scripts. and idk, i just never thought to combine them. never had a problem with the separately till i put them in the same brick Octocentillion 15 — 5y
0
Merge them, clean up the indentation, get rid of all the useless whitspace. DinozCreates 1070 — 5y

1 answer

Log in to vote
0
Answered by
sydre2 25
5 years ago

The problem is that you included the debounce = false before the end. In this case, if (human ~= nil) and debounce == false then the debounce = false will not run because you've put it after the else statement. To make the script work, you just need to move the debounce = false under one end statement and it will set debounce to false even if (human ~= nil) and debounce == false

Ad

Answer this question