Me and my friend on Roblox were playing one of those old Roblox simulator games, and we came to the topic of removing hats if they were made after 2007. I suggested finding the asset ID of the last hat made in '07, and if the number is greater than that it would remove the hat.
The thing is, I don't know how you would format an asset ID to put in a script, if it is even possible (I've seen it done before, but...)
I don't know if you would put something like http://www.roblox.com/asset/?id= or something before it, or just put the number...
Thanks in advance.
game.Players.PlayerAdded:connect(function(playerAdded) player.CharacterAdded:connect(function(characterAdded) if characterAdded.Accessory. --i think i'm on the right track here but idk then character.Accessory.Handle:Destroy() end end) end)
Edit: Here's what I think the script would look like. Yeah, all I've gotten to is the part where the player joins the game, and then the end part where the handle is destroyed if the assetID is above a certain number.
This probably will make all you experienced Lua users cringe, but this is what I have. Correct me if need be.
One method of doing this would be to loop through all the Hat
objects that a player is wearing. Inside each hat, there should be a Part
called "Handle" which contains a Mesh
object inside of it. You can read the MeshId
or the TextureId
properties of this Mesh
object to find the AssetId
of the hat.
(Keep in mind, however, that ROBLOX is currently transitioning into turning Hat
objects into Accessory
objects.)
Now, first, let's look at the MeshId
(you could use its TextureId
if you want, but for my example, I'm using MeshId
). MeshId
is a property that holds a String
something like this:
"rbxassetid://190770123"
However, we want just the numbers at the end, not the String. To do so, we would need to do utilize the match function for strings.
Here's how to do it:
-- New player enters the game game.Players.PlayerAdded:connect(function(player) -- The player's character loads/reloads player.CharacterAdded:connect(function(character) wait(1) -- Waits a second to allow accessories to load -- Loops through all the contents of the character -- Looks for any "Accessory" items for i, v in pairs(character:GetChildren()) do if v:IsA("Accessory") then -- We're only looking for Accessories local asset = v.Handle.Mesh.MeshId -- This is how to get only the numbers from the String local assetId = tonumber(asset:match("%d+")) end end end) end)
Now comes the part where we need to see if the Accessory
is from 2007 or not. If it isn't, we need to get rid of it. To do so, we need to use MarketplaceService.
Here's what the final script should look like after using MarketplaceService
:
local marketplaceService = game:GetService("MarketplaceService") -- New player enters the game game.Players.PlayerAdded:connect(function(player) -- The player's character loads/reloads player.CharacterAdded:connect(function(character) wait(1) -- Waits a second to allow accessories to load -- Loops through all the contents of the character -- Looks for any "Accessory" items for i, v in pairs(character:GetChildren()) do if v:IsA("Accessory") then -- We're only looking for Accessories local asset = v.Handle.Mesh.MeshId -- This is how to get only the numbers from the String local assetId = tonumber(asset:match("%d+")) -- Gets all the product information from the assetId local info = marketplaceService:GetProductInfo(assetId) -- Checks to see if the creation date is 2007 or not if string.sub(info.Created, 1, 4) ~= "2007" then v:Destroy() -- Destroys accessory if not end end end end) end)
Hope this helps! if it does, don't forget to click Accept Answer and +1 my Rep!