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

My script doesn't work multiple times?

Asked by 6 years ago
CurrentPrice = script.Parent.Worth
Debounce = true
PickedUp = false


script.Parent.Touched:Connect(function(hit)
    if Debounce and hit.Parent.Parent:FindFirstChild("Humanoid") and hit.Parent.Name == "Trashpick" and not PickedUp then
        print("Trash is now PickedUp")      
        Debounce = false
        script.Parent.Transparency = 1
        local player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent)

        player:FindFirstChild("leaderstats")
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + CurrentPrice.Value
        print("Player picked up trash")

        PickedUp = true
        wait(10)
        PickedUp = false
        script.Parent.Transparency = 0

    end

    end)

Here is my script, It works fine BUT it does not work MULTIPLE times. I would want to after the Transparency is set to = 0 I want the script to be working again, please help!

0
Try using while true do rochel89 42 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

I think you forgot to set the debounce to true again? I mean, line 09 sets the debounce to false and no other lines seem to put it back to true?

Try this I guess.

CurrentPrice = script.Parent.Worth
    Debounce = true
    PickedUp = false


    script.Parent.Touched:Connect(function(hit)
        if Debounce and hit.Parent.Parent:FindFirstChild("Humanoid") and hit.Parent.Name == "Trashpick" and not PickedUp then
            print("Trash is now PickedUp")     
            Debounce = false
            script.Parent.Transparency = 1
            local player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent)

            player:FindFirstChild("leaderstats")
            player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + CurrentPrice.Value
            print("Player picked up trash")

            PickedUp = true
            wait(10)
            PickedUp = false
        Debounce = true -- Resets variable Debounce back to true
            script.Parent.Transparency = 0

        end

        end)

Just a little mistake if I am right.

Ad

Answer this question