Badge Warning: How to fix?

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

image

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)

1 Like

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.

1 Like

I testet it in game (outside from studio) and i still get this Message…

The weird thing is that HERE the badges are Active, i tested with the same code and it works for me, i don’t really know what is that behavior

1 Like

im gonna cry now… roblox just hates me

Edit: this line:

if BadgeService:IsLegal(badgeId) and not BadgeService:IsDisabled(badgeId)

The ''Not disabled" means: The badge MUST BE ACTIVE.

do this:
if BadgeService:IsLegal(badgeId) and BadgeService:IsDisabled(badgeId)

1 Like

for example

local isDisabled = false
print(not isDisabled) -- Output: true 

local isDisabled = true
print(not isDisabled) -- Output: false

placing ‘‘not’’ before the variable or sentence will make it check for the OPPOSITE value
like above

also this Function is Deprecated, i recently checked this out, BadgeService | Documentação - Central de Criadores Roblox

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

1 Like

From the BadgeService:IsDisabled() documentation:

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”.

BadgeService:IsLegal() is also deprecated and will always return true.

Try this function:

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
2 Likes

Now i get this warning (in game and in studio)

Sorry, badges can only be awarded by Roblox game servers

1 Like

Disable it and test again the badge awarding code (since in Roblox studio you need to disable to make it work )

1 Like

Nope… still the same Warning…

Sorry, badges can only be awarded by Roblox game servers

: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.

2 Likes

Yeah, it’s a Roblox security feature.

He is correct ^^^

1 Like

Thanks for your help! It works now!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.