Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My Text Button Isn't Removing?

I'm trying to make this script remove the text button when the player have collected 10 coin or more, but it doesn't work. Did I put it in the wrong script? What did I do wrong? Can you guys help me?

You can look at this screen shot if you would like to see: http://prntscr.com/8lnoym

If you want the model, I can give it to you. So you could have a better of understanding:

http://www.roblox.com/My/Item.aspx?ID=311894614

local player = game.Players.LocalPlayer
repeat wait() until player.Character 

local stats = player:WaitForChild('leaderstats')
local statsname = "Points"
local guiname = "Unlock"

stats[statsname].Changed:connect(function()
    print('Changed')
    if stats:FindFirstChild(statsname) then
        print('IT EXISTS!')
        if stats[statsname].Value >= 10 then 
            print('VALUE EQUALS 10!')
            if player:WaitForChild('PlayerGui'):FindFirstChild(guiname) then
                print('found the gui')
                player.PlayerGui[guiname]:Destroy()
            end
        end
    end
end)

Many thanks, my friends!

1 answer

✓ Accepted answer

Hey bud, I'll help you out

First of all, you don't need to state the statsname in a variable. So you can get rid of these two:

local statsname = "Points"
local guiname = "Unlock"

Secondly, I removed all the prints for now to save me some time and eye sore. I removed the stats.Points because we already know the script checked for that. I check for the stats and end it on the same line to save some space.

local player = game.Players.LocalPlayer
local stats = player:WaitForChild('leaderstats')

stats:WaitForChild('Coins').Changed:connect(function()
    if stats.Coins.Value >= 10 then
        script.Parent:Destroy()
    end
end)

if stats.Coins.Value >= 10 then script.Parent:Destroy() end

I can always edit this if it doesn't work, so give me some feedback.

Update: I took your model and tested. You had no "Points" there were "Coins", I tested my code it worked, I did was changed the Points to Coins.

Update II: I added an extra line in there in case you die or reset the Unlock Blackout with be gone.

11 comments

0

I tested it and it doesn't work. Can you check if I made some error mistakes?

0

I updated the model so you can check it.

0

I updated my code, I explained what the problem was on the update

0

Thank you, my friend! 1 Point for you!!! :)

0

But there's is still one problem. When I reset, the text button come back. So I have to collect all the coins again for it to remove. Is there a way to make it remove permitted without having to collect it again when I reset?

0

I updated the model again, so you can check it.

0

I updated my code again, and you're welcome man

0

Ummm, can you help me again? I don't know how to explain this but I make a team selection for my sonic GUI and my text button isn't removing when I collected the coins. Again, I'm sorry to bothered you again. Can you help me? Please. D:

0

I updated the model again, so you can check it out.

0

Here is the link to the model: http://www.roblox.com/unnamed-item?id=313163376

0

Please, if you're online. :(

This discussion is preserved as it was. New answers, comments, and votes are closed.