I’m trying to give all players in the game a badge when the value is 1000 or higher
My current script looks like this it’s a serversided script:
local badgeService = game:GetService("BadgeService")
game.Players.PlayerAdded:Connect(function(player)
if player.PlayerGui:WaitForChild("mainUI").mainFrame.TextButton.Clicker.Amount.Value >= 1000 then
badgeService:AwardBadge(4139132345274602)
end
end)
Your code looks good, but for awarding the badge, you have to also put who you want to award the badge to.
badgeService:AwardBadge(4139132345274602, player)
You have to include the ‘player’ after the badge ID, because that is the player you’re awarding the badge to.
I don’t understand your question thoroughly, I don’t know if you wanted to give the badge to all the players or if you wanted to just give the badge to the player who joins the game and their Amount value is greater than or equal to 1,000.
But, if you want to give all the players in the game the badge, you can just this code here:
local badgeService = game:GetService("BadgeService")
local badgeID = 413913234527460
for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
if player.PlayerGui:WaitForChild("mainUI").mainFrame.TextButton.Clicker.Amount.Value >= 1000 then
badgeService:AwardBadge(player.UserId, badgeID)
end
end
game:GetService("Players").PlayerAdded:Connect(function(player)
if player.PlayerGui:WaitForChild("mainUI").mainFrame.TextButton.Clicker.Amount.Value >= 1000 then
badgeService:AwardBadge(player.UserId, badgeID)
end
end)
Thanks for your info, the game is based on “click it” (Click It! [POP CAT] - Roblox) i want to make something like that but without the countries, it’s a global clicking game so everyone in the world click on the same “value” it’s pointless but i’m really bored so i just made something like it
If you’re going to use AwardBadge, make sure to put it in a pcall as it can sometimes fail and stop the script from running.
You should also check for badges if player already owns it. You can use BadgeService:UserHasBadgeAsync to check. Make sure to also put that in a pcall aswell.
So far I see, the code does not work accurately because you run it as soon as the player joins the server. This means that (if their data is saved,) it will only check if their value is over the amount given when joining back.
To make sure that the badge is given as soon as the player reaches the amount required, make use of the .Changed event that Value instances can listen to.
Example:
local value = player.PlayerGui:WaitForChild("mainUI").mainFrame.TextButton.Clicker.Amount
value.Changed:Connect(function(value)
if value >= 1000 then
--//Award badge
end
end)