I made this code but i get a Warning in the Console
The script awards a badge to the local player when they press the space bar. The script uses Roblox’s built-in services (UserInputService and BadgeService ) to handle user input and award badges.
local player = game.Players.LocalPlayer
local userInputService = game:GetService("UserInputService")
local BadgeService = game:GetService("BadgeService")
local badgeId = 714850412665534 -- Replace with the ID of the badge you want to award
local function awardBadge(player, badgeId)
-- check badge can be awarded
if BadgeService:IsLegal(badgeId) and not BadgeService:IsDisabled(badgeId) then
-- award badge
BadgeService:AwardBadge(player.UserId, badgeId)
end
end
userInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Space then
print("Space bar pressed!")
awardBadge(player, badgeId)
end
end)
The Script is in the StarterPlayerScripts as a local Script
The Error i get:
Sorry, badges can only be tested if they are disabled on Roblox game servers
I dont know how to fix it…
(the badge is not Disabled)
Not 100% sure as I don’t work with badges really but maybe it’s saying it rather needs to be disabled to test in studio? Maybe it’s not possible to award badges in studio but needs to be on actual servers as they need to communicate with roblox endpoints to do so.
that’s why we always need to check the current state of the functions and methods we are using, even if it is from Roblox, they change constantly so Double-check what is happing before you write your code, this really is annoying sometimes
In Studio, a badge can only be tested if it is disabled. Calling this function with an enabled badge in Studio will return true and produce a warning “Sorry, badges can only be tested if they are disabled on Roblox game servers”.
local function awardBadge(player: Player, badgeId: number): ()
local success: boolean, response: any = pcall(
BadgeService.GetBadgeInfoAsync,
BadgeService,
badgeId
)
if not success then
warn("Error getting badge info: " .. response)
return
end
if response.IsEnabled then
BadgeService:AwardBadge(player.UserId, badgeId)
end
end
:AwardBadge() has to be called from a server or module script. You cannot award badges from the client. Create a remote event that fires to the server when the player jumps, then the server can award it.