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

Why is this badge giving script not working?

The script is supposed to award the badge when a stat becomes a certain value. However, it is not working, and I have no idea why. Can someone please help me?

Script:

local BadgeID = 238037695
local Cash = "Friends"
game.Players.PlayerAdded:connect(function(p) 
repeat wait() until p:findFirstChild("Friends") ~= nil 
p[Cash].Changed:connect(function() 
if p[Cash].Value == 1 then return end 
game:GetService("BadgeService"):AwardBadge(p.userId, BadgeID) 
end) 
end) 

2 comments

0

Can you provide an error message?

0

That involves the Dev GUI, right?

1 answer

✓ Accepted answer

There is a method called WaitForChild. Use that instead of a repeat loop.

Here:

local badgeId = 238037695;
local statName = "Friends";
local neededVal = 1;
local serv = game:GetService("BadgeService");

game.Players.PlayerAdded:connect(function(plr)
    local stat = plr:WaitForChild(statName);
    stat.Changed:connect(function()
        if stat.Value == neededVal then
            serv:AwardBadge(plr.userId, badgeId)
        end
    end)
end)

Let me know if that works. Also if you're trying to award to yourself, that won't work. Use an alternate account.

Edited on 4/21/15: fixed errors caused by mobile

3 comments

0

It works. Had to do some editing, but it worked. Thanks!

0

May I ask what needed editing?

0

Never mind. Sorry for those two errors. Typed that up on my phone, and I guess I missed all the autocorrections.

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