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. I don’t want it to be connected to anything in your backpack, I tried a script that was connected to backpack and it kicked everyone in general, whether you owned the item or not.
Well you’ll need some way to detect if the player is currently wearing the item. Best way to do this is the MeshId, Mind giving me a screenshot of the explorer of a character with the item on?
here you go:
CheckHat.lua (592 Bytes)
local Players = game:GetService('Players')
local meshId = 'rbxassetid://5830800095' -- change with desired hat meshid to check
Players.PlayerAdded:Connect(function(player)
player.CharacterAppearanceLoaded:Connect(function(character)
local found
for i, v in character:GetChildren() do
if v:IsA('Accessory') then
local handle = v:FindFirstChildOfClass('MeshPart')
if handle and handle.MeshId == meshId then
found = true
break
end
end
end
if not found then
player:Kick(string.format('Missing required hat %q', meshId))
end
end)
end)
why would you get the mesh of the item instead of the item ID itself?
local hatID = 15008291624 – this is the ID of a random UGC item
– cool services
local players = game:GetService(“Players”)
local marketplaceService = game:GetService(“MarketplaceService”)
– do the player be owning the hat tho
local function doesPlayerOwnHat(player)
local success, doesPlayerOwnAsset = pcall(marketplaceService.PlayerOwnsAsset, marketplaceService, player, hatID)
return success and doesPlayerOwnAsset
end
– validate like a chad
local function onPlayerJoin(player)
local hasHat = doesPlayerOwnHat(player)
if hasHat then
print(player.Name .. " has the hat!")
else
print(player.Name .. " does not have the hat :(")
player:Kick("only people who have a certain hat can enter")
end
end
– when a new player joins, empty the compartments of their pantaloons
players.PlayerAdded:Connect(onPlayerJoin)
i do not know how to format my code so i would like to apologize to anyone reading this
i haven’t ever used marketplaceservice but that looks like a better solution to me
marketplace service is absolutely worth looking into