Why is this badge giver not working correctly? I have the correct id and everything.
local BadgeID = 2128142670
local Cash = "Wins"
local HowMuch = 3
game.Players.PlayerAdded:connect(function(p)
repeat wait() until p:findFirstChild("leaderstats") ~= nil
p.leaderstats[Cash].Changed:connect(function()
if p.leaderstats[Cash].Value <= HowMuch - 1 then return end
game:GetService("BadgeService"):AwardBadge(p.userId, BadgeID)
end)
end)
Does it get past the repeat? If not, (but it would be good to do this anyway) replace the until p:findFirstChild("leaderstats") ~= nil with until p:findFirstChild("leaderstats")
I can’t remember exactly how Changed works, but I think it would be good to use GetPropertyChangedSignal("Value") instead.
If none of these work, how far does it get before it doesn’t work?
Also, I have simplified your script, eventually maybe fixed your problem as well, it worked for me.
local BadgeID = -- Badge Id --
local Cash = "Wins"
local BadgeService = game:GetService("BadgeService")
local HowMuch = 3
game.Players.PlayerAdded:connect(function(player)
if player:WaitForChild("leaderstats"):FindFirstChild(Cash) then
player.leaderstats[Cash].Changed:Connect(function(NewPoints)
if NewPoints >= HowMuch then
BadgeService:AwardBadge(player.UserId,BadgeID)
end
end)
end
end)
I think AnotherPenguin solved this, but heres my script, idk if you need it
local leaderstats = player.leaderstats
local Cash = "Wins"
local badgeService = game:GetService("BadgeService")
local badgeId = 0
if Cash.Value >= 5 then
badgeService:AwardBadge(player.UserId, badgeId)
end
This is what I put inside one of the scripts as well and it is only printing out 2 in the output.
local BadgeID = 2128142670
local Wins = "Wins"
local BadgeService = game:GetService("BadgeService")
local HowMuch = 3
game.Players.PlayerAdded:connect(function(player)
print("2")
if player:WaitForChild("leaderstats"):FindFirstChild(Wins) then
print("3")
player.leaderstats[Wins].Changed:Connect(function(NewPoints)
print("4")
if NewPoints >= HowMuch then
print("5")
BadgeService:AwardBadge(player.UserId,BadgeID)
print("6")
end
end)
end
end)