Help with ReplicatedStorage to Backpack

Hey, I made an inventory system for my game so when we equip a tool (with scripts in it) it clone the object in replicated storage, and then paste it in the player’s backpack but when the tool arrives in the backpack it is impossible to run the tool’s script… How can I make the scripts work once they are in the player’s backpack?

I precise that the tool isn’t working ONLY when the tool is cloned from the inventory script. if it is cloned from any other script the tool will work no problem… I don’t know what’s the problem there is no error in the whole inventory script or game itself. Thank you!

1 Like

Does it give some errors in the output?

1 Like

None, not a single error in the whole game

Make sure that cloning is started from the server script, and not from the local script.
Try using Remote Event to work with local and server servers.

Don’t worry I know that, the local script only gets the object name, then fire a remote event and the serverscript find the tool and clone it.

Even from a local script it should work for the client. I wouldn’t only appear for other players

well there is no error in my outpout. I will try to find an alterantive to this but meanwhile if someone can help me it would be great! Thanks for your answer.

Can you share the script that you’re using? It’s pretty hard to solve a problem without knowing the script or some errors abt it

Unfortunately, I will not be able to help you without additional context, since there can be a lot of ramifications of the problem. If you have such an opportunity, provide your script, its location and the elements with which it interacts.

1 Like

Ok so here is the local script that get the tool name if the player claimed the tool

local inventoryFolder = game.Players.LocalPlayer:WaitForChild("Inventory")
function updateInv()
	
	for i, child in pairs(script.Parent.InventoryScroller:GetChildren()) do
		if child:IsA("TextButton") then child:Destroy() end
	end
	
	for i, item in pairs(inventoryFolder:GetChildren()) do
		
		if item.Value > 0 then
			

			local displayItem = game.ReplicatedStorage.Items[item.Name].ImageID
			
			local newButton = script.ItemButton:Clone()
			newButton.ItemName.Text = item.Name
			newButton.Count.Text = item.Value
			newButton.ItemFrame.Image = displayItem.Value
			
			
			local ITEMFOLD = game.ReplicatedStorage.Items
			--Debounce (these are just the weapon's category so the player is unable to equip 2 swords for exemple.
			local MeleeDB = true
			local FistDB = true
			
			newButton.MouseButton1Click:Connect(function()
				
				if MeleeDB and ITEMFOLD[item.Name].Class.Value == "Melee" then
					MeleeDB = false
					local Hum = game.Players.LocalPlayer.Character.Humanoid
					game.ReplicatedStorage.InventoryRE:FireServer("Melee", item.Name, Hum)
					wait(1)
					MeleeDB = true
				elseif FistDB and ITEMFOLD[item.Name].Class.Value == "Fist" then
					FistDB = false
					local Hum = game.Players.LocalPlayer.Character.Humanoid
					game.ReplicatedStorage.InventoryRE:FireServer("Fist", item.Name, Hum)
					wait(1)
					FistDB = true
				
				end
				
			end)
		
			newButton.Parent = script.Parent.InventoryScroller
		end
	end
	

And here is the server script that clone the tool

game.ReplicatedStorage.InventoryRE.OnServerEvent:Connect(function(p, instruction, itemName, hum)
	
	if instruction == "Melee" and p.Inventory:FindFirstChild(itemName) and p.Inventory[itemName].Value > 0 and CanSwitchMelee then
		local newItem = game.ReplicatedStorage.Items[itemName]:Clone()
		CanSwitchMelee = false
		
		local Tool = Instance.new("Tool", p.Backpack)
		Tool.Name = newItem.Name
		newItem.Parent = Tool
		
		repeat
			task.wait()
		until hum.Health <= 0
		wait(3)
		CanSwitchMelee = true
	elseif instruction == "Fist" and p.Inventory:FindFirstChild(itemName) and p.Inventory[itemName].Value > 0 and CanSwitchFist then
		game.ReplicatedStorage.Items[itemName]:Clone().Parent = p.Backpack
		CanSwitchMelee = false

		repeat
			task.wait()
		until hum.Health <= 0
		wait(3)
		CanSwitchFist = true
	
		
	end
end)

My scripts are listed in another reply, you can check it out if you want but there’s a lot of information.

Set the tool scripts’ Enabled boolean to false in ReplicatedStorage and set it to true after moving the tool over to the Backpack. This ensures the script only starts its thread in the Players’ Backpack.

Yup, I indeed tryed that, but impossible to find the script when the tool is cloned. If i try to enable it back via another script it’ll just say that the item that i’m trying to clone doesn’t contain a script, but it does.

Have you tried using Tool:WaitForChild(Script)?

I think I did, just in case I’m going to try that rn.

Infinite yield possible, it’s not working.

Then your problem is that you’re not cloning the actual localscript properly, check if Archivable is enabled, if it is, then you will have to likely change the location of all of your tools to ServerStorage and not ReplicatedStorage.

Just tried that but serverstorage deletes all my items. I never encountered such a problem haha

Ehhhh that’s gonna be very embarassing but emm, I fixed it- I don’t know what was the problem but the only thing I did was to paste a new version of the VFX of the tool in it and it… somehow work… I’m confused but i’ll save the whole code in notes so if I ever get something I’ll be able to fix it.

Thank you for your precious time @Tetraic!

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