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

How to award a badge when the player has over 1,000 EXP?

Asked by 6 years ago

Hello everyone!

So I have a game, and I'm trying to make it so a player receives a badge when they have over 1,000 EXP.

Now I'm not good at scripting, but I tried to script it anyways. It didn't work.

Can someone help me with this, please?

local badgeId = 1390726909
local badgeService = game:GetService("BadgeService")

local function onEntered(player)
    wait(5)
    local hum = player:FindFirstChild("Humanoid")
    if hum then
        if player.leaderstats.EXP.Value<=1000 then
            badgeService:AwardBadge(player.userId, badgeId)
        end
    end
end

game.Players.PlayerAdded:connect(onEntered)
0
btw. :connect is depreciated. Use :Connect Axceed_Xlr 380 — 6y
0
Also, I advise you use datastores instead of leaderstats, but that's a bit more advanced. Robin5D 186 — 6y
0
Ok. Harrydamastr 35 — 6y

2 answers

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

Assuming you already have a script to create the EXP leaderstat, you can try something like this which will check every time the EXP changes.

local badgeId = 1390726909
local badgeService = game:GetService("BadgeService")

local function onEntered(player)
    player:WaitForChild("leaderstats"):WaitForChild("EXP").Changed:Connect(function(newExp)
        if newExp >=1000 then
            if not badgeService:UserHasBadge(player.UserId,badgeId) then
                badgeService:AwardBadge(player.userId, badgeId)
            end
        end
    end)
end

game.Players.PlayerAdded:connect(onEntered)

Also, Humanoid isn't inside of the player, it's inside of the character. However, with PlayerAdded you shouldn't need to do this check.

0
Thank you. I understand now :) Harrydamastr 35 — 6y
Ad
Log in to vote
0
Answered by
Dad_Bot 34
6 years ago

This only fires when the player joins the game, not sure if this is what you're going for. You also have the greater than value flipped. Line 8 should look like

if player.leaderstats.EXP.Value>=1000 then

This is if you want it to be greater than or equal to 1000. Hope this helped.

0
Thank you. :) Harrydamastr 35 — 6y

Answer this question