Hii, so I wanted to try and make a script, where if the player has a certain badge they can join the game. If they don't have it then it kicks them with the message of saying you don't have this badge or whatever.
-- variables below
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local BADGE_ID = 2124499744
local player = script.Parent.Parent
local plr = Players:GetPlayerFromCharacter(BADGE_ID)
while true do
wait(0.001)
if plr and BadgeService:UserHasBadgeAsync(plr.UserId, BADGE_ID)then
print("Welcome!")
-- basically prints into the output welcome if they have the badge
else
player:Kick("You don't have the flashlight!")
-- if they don't have the badge, then it kicks you from the game.
end
end
When I test the game it says in output: -- Unable to cast value to object
I'm using someone else's badge before I use my own. And the script is placed into StarterPack, idk if it has to do something with that. But, it's a regular script.
I read this website already, btw which is here.
I don't know what is wrong with the script, or if it is just roblox. I hope you can use other player's badges.

1 comment
I realized that, after my friend pointed it out a hour after I posted this. Sorry! I was tired, and I didn't realize lol.