I made a script that gives a badge when a player earns 100 points.
It checks whether the player already has a badge when the player enters the game, then it checks the points to award the badge.
I want to know if theres anything I need to fix or improve it
heres the code:
local badgeservice = game:GetService("BadgeService")
local badgeId = 000000
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Wait()
local lead = Instance.new("IntValue", plr)
lead.Name = "leaderstats"
local points = Instance.new("IntValue", lead)
points.Name = "points"
local success, hasbadge = pcall(function()
return badgeservice:UserHasBadgeAsync(plr.UserId, badgeId)
end)
if not success then
plr:Kick("data load failed. Please try again")
end
if not hasbadge then
local c
local function pointschanged()
if points.Value >= 100 then
local success = pcall(function()
badgeservice:AwardBadge(plr.UserId, badgeId)
end)
if success then
c:Disconnect()
end
end
end
c = points:GetPropertyChangedSignal("Value"):Connect(pointschanged)
end
end)