Hi im making a badge with a value but without a leardstats
I try this but Badge is not awarding
The code:
local plr = game.Players.LocalPlayer
local bsv = game:GetService(“BadgeService”)
local id = 1356698128556520
while wait(0.5) do
if script.Parent.Value >= 10 then
if not bsv:UserHasBadgeAsync(plr.UserId, id) then
bsv:AwardBadge(plr.UserId, id)
plr.PlayerGui.BrickSucess.Enabled = true
wait(2)
plr.PlayerGui.BrickSucess.Enabled = false
end
end
end
I’m back with a Badge to test with and some research! (Tested)
--server script in ServerScriptService
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local badgeID = 1531211754736160
function Spawned(player)
task.wait(1.1)
local hasBadge = false
local success, message = pcall(function()
hasBadge = BadgeService:UserHasBadgeAsync(player.UserId, badgeID)
end)
if not success then
warn("Checking Badge: " .. tostring(message))
return
end
if hasBadge then
print("has badge")
-- maybe do stuff
else
BadgeService:AwardBadge(player.UserId, badgeID)
end
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
Spawned(player)
end)
end)
Dani I don’t know about you but I fail till I get it right. At some point I will always get it right.
Note: after making the badge I had to save the program to Roblox (also compiled) for this to work.
heres an example to how the server script should turn out, i dont have much context but ya
local Players = game:GetService('Players') :: Players
local BadgeService = game:GetService('BadgeService') :: BadgeService
local BadgeId = 1356698128556520
task.spawn(function() -- considering you prob wouldnt know how to add a while loop in a server script
while true do
task.wait( 0.5 ) -- use task.wait not wait
if true then -- your statement or whtv
for __ , Player in Players:GetPlayers() do
local UserId = Player.UserId
if not BadgeService:UserHasBadgeAsync( UserId , BadgeId ) then
BadgeService:AwardBadge( UserId, BadgeId )
-- other stuff you want down below, etc
end
end
end
end
end)