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.
I assume the problem is coming from here
local plr = Players:GetPlayerFromCharacter(BADGE_ID)
BADGE_ID
is a number, this method expects a character object, to get the player from, so you need the character first
Also, don't you already have the player?
local player = script.Parent.Parent
Why are you creating another one
I spotted this:
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 -- you forgot the space print("Welcome!") else player:Kick("You don't have the flashlight!") end end
It might just be a typo and not the problem but if it is please accept this as your answer.
All the best fruits,
PrismaticFruits - obviously a very talented scripter