Replacing owned gears with a new version of it upon joining the experience

Hey, so this is my first time making a topic in here (i am kind of intimidated)

LoadLibrary has been deprecated for a while, so i went and fixed certain gear. As Roblox still allows you to use the “Allowed Gear” option in a way (it’s “hidden” in Places, [PLACE NAME] and Permissions as Gear Settings), which allows any gear the player has in their inventory (which is what i mean by owned) to be used in the game.

However, as we all know, a lot of them are broken due to the LoadLibrary deprecation, like the Golden Bow and Arrow. Is there a way to make it so it makes a “check” of the player’s inventory or the gear’s ID and replace it with the fixed version? The fixed versions are in ServerStorage (In a folder called FixedGear, if that matters).

The thing is: i don’t know if this will conflict with the game’s Gear Settings itself, so the player may end up having two versions of the gear, which i don’t really want.

If this is considered off-topic or any other reason, please close/remove the post. i am terribly sorry.

The player’s gear will be inserted into their StarterGear folder, which exists under their Player instance alongside the backpack. Check for anything that currently exists or will exist in the folder (using Instance.ChildAdded) that has a counterpart version in the “FixedGear” folder by name. If it does, replace that gear. Doing so will trigger the ChildAdded event, so add an attribute to flag the tool as a replacement

2 Likes

Also note that I don’t believe there is a way to get the gear ID from an inserted gear, so I think you’ll need to have the Tool names of the gear (which you can get from inserting the models).

I’d recommend Ziffix’s way but if you want you can check the player’s inventory with AvatarEditorService:GetInventory (though I think it potentially prompts for permission if the player has their inventory set to private). The main/only benefit of this is you can do it using gear ID, though you might need to insert the gear items to get the Tool names to remove the duplicates, or use a pre-made list.

Also this is the right category and a well written topic :slight_smile:

1 Like

Will try that out, thank you.

How could this be done as a script? the game also has a gear spawner GUI, and the overwriting system uses the gear’s ID and internal name (the name of the Tool), if you want an example.

As mentioned above, i bought the Golden Bow and Arrow years ago, and of course, it doesn’t work nowadays. The name of the tool is “OrnateGoldenBow”.

in the ModuleScript, it’s currently like this: {id = 204485737, gearName = 'OrnateGoldenBow'},, and it overwrites with the one in FixedGear.

I will see if i should/could put it on the main script (called GearServer, could post how it looks like to you) or make another script of it’s own, as i don’t know if it will conflict with the spawner GUI.

As BendsSpace mentioned, the AvatarEditorService seems like a good thing to put, also.

It’s fine if you don’t want to do it, i don’t consider myself as proficient in scripting. I was just wondering if the thing i wanted to do was possible.

Something like this should work:

-- Script in ServerScriptService or Workspace

-- A table mapping Roblox gear names to a fixed version
local ServerStorage = game:GetService("ServerStorage")
local replacements = {
    ['OrnateGoldenBow'] = ServerStorage.FixedGear.OrnateGoldenBow
    -- ...
}

game:GetService("Players").PlayerAdded:Connect(function(player)
    player:WaitForChild("StarterGear").ChildAdded:Connect(function(child)
        -- If the child is already a fixed gear
        if child:GetAttribute("Fixed") then return end

        -- Check if the new gear should be replaced
        if replacements[child.Name] then
            -- Replace the added gear with a fixed version
            child:Destroy()
            local clone = replacements[child.Name]:Clone()
            clone:SetAttribute("Fixed", true)
            clone.Parent = player.StarterGear
        end
    end)
end)
1 Like

It doesn’t seem to be working. It hasn’t replaced the broken version given by the Gear Settings/Allowed gear given by what i would assume Roblox itself. Maybe it’s rooted to it and you can’t really replace it? Or do i have to change something else? I can give you a bit of the code to see how the gear spawner GUI replaces it with the ones in ServerStorage.

The code itself isn’t giving me any errors when i load in the game though, both in Studio or the Roblox client.

Here’s a bit of the code for the gear spawner, don’t know if anything is conflicting

local function getAsset(asset: number)
	local sucess, gear = pcall(InsertService.LoadAsset, InsertService, asset)
	if sucess then

		for _, obj in pairs (gear:GetDescendants()) do
			if obj:IsA("Tool") then
				gear = obj
			end
		end
		return gear
	end
end

local function giveGear(player: Player, assetID: number)
	local gearAsset: Tool? = nil
	local needsFixed = false

	-- we loop through the module to find the matching id
	-- then we get the name from gear.GearName
	-- if found we set needsFixed to true to indicate it's a fixed gear
	for _, gear in pairs(fixedGears) do
		if assetID ~= gear.id then continue end
		gearAsset = gearStorage:FindFirstChild(gear.gearName):Clone()
		needsFixed = true
	end

	-- if the gear works on their own, then we use the :LoadAsset() to get it from the catalog
	if not needsFixed then
		local asset = getAsset(assetID)
		if asset then
			gearAsset = asset:Clone()
		end

	end

	-- in case anything goes wrong, we don't want it to error if it's nil
	if gearAsset ~= nil then
		if player.Backpack:FindFirstChild(gearAsset.Name) or player.Character:FindFirstChild(gearAsset.Name) then
			return
		end
		gearAsset:SetAttribute('spawned', true)
		gearAsset.CanBeDropped = false
		gearAsset.Parent = player.Backpack
	end
end

the part with the names and IDs for the ModuleScript inside this code (called GearServer, ModuleScript is called FixedGear) is just

return {
	{id = 0000000, gearName = 'GEAR-NAME'},
}

and it works, somehow. Could be conflicting with the names.

Nevermind, it seems that the gear does get replaced, but when clicking on it, i get nothing equipped, it’s simply there, but the player character doesn’t equip it at all in the game. Before the script, i would get the gear, but it would obviously be broken, so when clicking it wouldn’t do anything (depending on the gear), but it would show the player with the gear equipped. Maybe the model isn’t loading, so it’s almost there.

There may have gears with duplicate names, maybe it could be done alongside the gear IDs, but it seems to be semi-functional with names.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.