Sorry, badges can only be awarded by Roblox game servers

I’ve tried everything and I can’t give players badges. Currently I’m firing an event from the client to the server and sending the badge Id through it.

Client script:

game.Players.LocalPlayer:WaitForChild("leaderstats").Level:GetPropertyChangedSignal("Value"):Connect(function()
	if game.Players.LocalPlayer.leaderstats.Level.Value == 1 then
		game.ReplicatedStorage.BadgeEvents.LevelUp:FireServer(2148468763)
	end
end)

Server script:

game.ReplicatedStorage.BadgeEvents.LevelUp.OnServerEvent:Connect(function(Player, Id)
	BadgeService:AwardBadge(Player.UserId, Id)
end)

All im getting is the warning that badges can only be awarded by roblox game servers. It even does this when I’m testing in roblox not in studio.

Check that your badge meets these requirements.

Just use a server script.
Not only it is unnecessary to have a localscript listen to a property then fire an event, but also very dangerous since exploiters can fire that event without having to move a muscle.

The reason your script is returing an error, because BadgeService is not live in Studio, this means that it should work in-game (when you join via the Roblox Client), but it won’t work in Studio.
I realised that you wrote this in the post, I accidentally skipped it, sorry :smiling_face_with_tear:

Put this code into a script in ServerScriptService:

--// Services
local Players = game:GetService('Players')
local BadgeService = game:GetService('BadgeService')

--// Variables
local BadgeID = 2148468763

--// Functions

local function OnPlayerAdded(Player:Player)
  local Value = Player.leaderstats.Level
  Value:GetPropertyChangedSignal('Value'):Connect(function()
    if Value.Value == 1 then
      local Success, HasBadge = pcall(function()
        return BadgeService:UserHasBadgeAsync(Player.UserId, BadgeID)
      end)
      if not HasBadge then
        local Success, Error = pcall(function()
          BadgeService:AwardBadge(Player.UserId, BadgeID)
        end)
      end
    end
  end)
end

--// Connections
Players.PlayerAdded:Connect(OnPlayerAdded)
1 Like