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

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

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)

3 comments

0

btw. :connect is depreciated. Use :Connect

0

Also, I advise you use datastores instead of leaderstats, but that's a bit more advanced.

0

Ok.

2 answers

✓ Accepted answer

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.

1 comment

0

Thank you. I understand now :)

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.

1 comment

0

Thank you. :)

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