I’m trying to make a game where you need to own a certain accessory in your inventory or be wearing it when you join the game. If that player doesn’t own it, they would be kicked.
1 Like
You could maybe create something like this.
I’m not able to test my code as of now, so just let me know if it doesn’t work
local function checkAccessory(player)
local requiredAccessoryId = 1234567890 -- Put your actual Roblox AccessoryID here
local hasAccessory = false
local backpack = player.Backpack
if backpack then
for _, item in pairs(backpack:GetChildren()) do
if item:IsA("Accessory") and item.Handle and item.Handle.AccessoryId == requiredAccessoryId then
hasAccessory = true
break
end
end
end
if not hasAccessory then
local character = player.Character
if character then
for _, accessory in pairs(character:GetChildren()) do
if accessory:IsA("Accessory") and accessory.Handle and accessory.Handle.AccessoryId == requiredAccessoryId then
hasAccessory = true
break
end
end
end
end
if not hasAccessory then
player:Kick("Kicked") -- Handle this
end
end
game.Players.PlayerAdded:Connect(checkAccessory)
2 Likes
This is good but there is a more efficient way of checking if player has an accessory that is using the :GetAppliedDescription
Function which returns a humanoiddescription instance, that instance has a method called :GetAccessories
and it returns ALL the equipped accessories then you can just loop through the table and check id, if it isn’t there then just kick at the end.
2 Likes
True, thats also a way of doing it
2 Likes
This works but I had someone test who owns the accessory, and it kicks them too, even if they wear it in game.