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

How to give players a badge upon reaching a certain amount of points/score?

Asked by 1 year ago
Edited 1 year ago

I am making a leaderboard for the number of times people ride roller coasters in my game, and I am trying to add a way to give players badges when they reach a certain level. The levels I am going to add are 50, 100, 200, 300, but I can't even get the first one to work.

Code:

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local Coasters = Instance.new("IntValue")
Coasters.Name = "Coasters"
Coasters.Parent = leaderstats


local BadgeService = game:GetService("BadgeService")
local badgeid = --BadgeID Here

    Coasters:GetPropertyChangedSignal("Value"):Connect(function(value)
        if value >= 50 then
        BadgeService:AwardBadge(badgeid)

    end
    end)
    end)
0
I am also beginner and I dont know if this is case but this will award badge after it becomes 51 because of >= Sabailuridze 126 — 1y
0
No because of >= means if it's 50 or above 50 then it's good MattVSNNL 620 — 1y

2 answers

Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
1 year ago

I immediately saw the problem, actually 2 problems!

  1. You're are not doing a while loop, otherwise it's gonna only check once and not ever again!
  2. You did value in the parameters no need for that since you can already check the Coasters Value!.

Here's your new code:

game:GetService("Players").PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local Coasters = Instance.new("IntValue")
    Coasters.Name = "Coasters"
    Coasters.Value = 0
    Coasters.Parent = leaderstats

    local BadgeService = game:GetService("BadgeService")
    local badgeid = 0

    coroutine.resume(coroutine.create(function() -- Corountine loop so we don't disturb code below it!
        while wait() do
            Coasters:GetPropertyChangedSignal("Value"):Connect(function()
                if Coasters.Value >= 50 then
                    BadgeService:AwardBadge(badgeid)
                end
            end)
        end
    end))
end)
0
Thank you very much! Jake821181 2 — 1y
0
Np MattVSNNL 620 — 1y
Ad
Log in to vote
0
Answered by
enes223 327 Moderation Voter
1 year ago

hey you! have you ever heard of enes? if you are in trouble, better call enes!

Answer this question