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

Why is this badge giving script not working?

Asked by 9 years ago

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) 
0
Can you provide an error message? Thewsomeguy 448 — 9y
0
That involves the Dev GUI, right? CoolJohnnyboy 121 — 9y

1 answer

Log in to vote
0
Answered by
DrJonJ 110
9 years ago

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

0
It works. Had to do some editing, but it worked. Thanks! CoolJohnnyboy 121 — 9y
0
May I ask what needed editing? DrJonJ 110 — 9y
0
Never mind. Sorry for those two errors. Typed that up on my phone, and I guess I missed all the autocorrections. DrJonJ 110 — 9y
Ad

Answer this question