I am making a Welcome Badge in Roblox, and I just encountered the most simple error, yet so difficult to solve. I made a module script called “Badge Handler”, and it contains a shared function that will basically accept a BadgeID and a Player. I tried to use as less lines as possible, and here is how it turned out:
local BadgeHandler = {}
local BadgeService = game:GetService("BadgeService")
function BadgeHandler.Award(BadgeId: NumberValue, Player: Player)
BadgeService:AwardBadge(Player.UserId, BadgeId)
end
return BadgeHandler
Pretty simple right?
On the other end, a server script in ServerScriptService
is calling the function with this text of code:
local BadgeHandler = require(script.Parent.Parent["Badge Handler"])
game.Players.PlayerAdded:Connect(function(Player: Player)
BadgeHandler:Award(2390214597728677, Player)
end)
Also very simple.
What could possibly go wrong? Well, for some reason, the module script does not accept the UserID of the player, with the following error:
19:42:13.014 ServerScriptService.Badges.Badge Handler:6: attempt to index number with ‘UserId’ - Server - Badge Handler:6
I can’t wrap my head around it. How could I mess up so badly, that an error would pop on my output in the simplest text of code?
I am very confused and I didn’t want to come up with posting on the DevForum, but here I am.