Can't award badge for some reason

I’ve been trying to award a badge when player clicks on textButton, but something went… wrong. I can’t see any reason why. It, for no visible reason gives out Unable to cast Instance to int64 - Server - ServerHandler:24 error. What could be possible reason to that

Local Script:

local Players = game:GetService("Players")
local LocPlr = Players.LocalPlayer
local UID = LocPlr.UserId

local RemoteEvent = game.EssentialsService.Remotes.Extras.AwardBadge

script.Parent.MouseButton1Click:Connect(function()
	RemoteEvent:FireServer(UID, 4180731781926470)
end)

Server Script (Function only):

local function AwardBadgePlayer(PlayerUserId, BadgeId)
	game.BadgeService:AwardBadge(PlayerUserId, BadgeId)
end

First parameter to any OnServerEvent callback will always be the player that fired the remote. This is automatic.

local badgeS = game:GetService("BadgeService")

local function AwardBadgePlayer(player:Player, userId:number, badgeId:number)
    local success, result = pcall(badgeS.AwardBadge, badgeS, player.UserId, badgeId)
    if not success then warn(result) end
end

Just to note this is kind of exploitable especially trusting the client on when to award badges. Consider a redesign.

Thanks!
About exploitability of function, I’m not really planning on adding badges besides “completed the tutorial” as of now so there’s nothing to exploit. The button is just “skip” incase someone will be lazy to complete it. Incase i’ll consider adding more badges, i will redesign function.

1 Like

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