Accepting model as tool not working

Soooo im using and advance melee system which basically uses a model as tool. I also have an inventory system which saves said tool along with a backpack gui. Now the backpack UI works if the item is a tool but I wanna be able to use a model as the tool instead. I know it can be done cause if I used the melee systems UI it works… Just doesnt work for mine. If I convert the model to a tool it breaks the melee system.

BACKPACK MAIN two scripts

Players = game:GetService("Players");
Player = Players.LocalPlayer;
Backpack = Player:FindFirstChildOfClass("Backpack");
UiFrame = script.Parent.UiFrame;
SlotsFolder = script.Parent.Slots;
if not Player.Character then
	Player.CharacterAdded:Wait();
end;
Char = Player.Character;
EquippedVal = require(script.InvSystem)(SlotsFolder);
function setIcon(p1)
	local v1 = nil;
	local v2 = UiFrame:FindFirstChild(p1.Name);
	if v2 then
		v1 = p1.Value;
		if v1 then

		else
			v2.Visible = false;
			return;
		end;
	else
		return;
	end;
	v2.Visible = true;
	v2.Item.Text = v1.Name;
end;
for v3, v4 in pairs(SlotsFolder:GetChildren()) do
	setIcon(v4);
	v4.Changed:connect(function()
		setIcon(v4);
	end);
end;
EquippedVal.Changed:connect(function()
	for v5, v6 in pairs(UiFrame:GetChildren()) do
		if v6:IsA("ImageButton") then
			v6.ImageTransparency = 0.5;
		end;
	end;
	if EquippedVal.Value then
		local v7 = UiFrame:FindFirstChild(EquippedVal.Value.Name);
		if v7 then
			v7.ImageTransparency = 0.2;
		end;
	end;
end);
for v8, v9 in pairs(UiFrame:GetChildren()) do
	if v9:IsA("ImageButton") then
		v9.MouseButton1Click:Connect(function()
			local v10 = SlotsFolder:FindFirstChild(v9.Name);
			if v10 then
				if EquippedVal.Value ~= v10 then
					EquippedVal.Value = v10;
					return;
				end;
			else
				return;
			end;
			EquippedVal.Value = nil;
		end);
	end;
end;
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false);

INVENTORY SYSTEM FOR BACKPACK

return function(p1, p2)
	p2 = p2 and true;
	local l__UserInputService__1 = game:GetService("UserInputService");
	local l__LocalPlayer__2 = game:GetService("Players").LocalPlayer;
	local v3 = Instance.new("ObjectValue");
	v3.Name = "Equipped";
	if not l__LocalPlayer__2.Character then
		l__LocalPlayer__2.CharacterAdded:Wait();
	end;
	local u1 = l__LocalPlayer__2:FindFirstChildOfClass("Backpack");
	local l__Character__2 = l__LocalPlayer__2.Character;
	local function u3()
		local v4 = {};
		for v5, v6 in pairs(u1:GetChildren()) do
			if v6:IsA("Tool") then
				table.insert(v4, v6);
			end;
		end;
		for v7, v8 in pairs(l__Character__2:GetChildren()) do
			if v8:IsA("Tool") then
				table.insert(v4, v8);
			end;
		end;
		return v4;
	end;
	local function u4(p3)
		for v9, v10 in pairs(p1:GetChildren()) do
			if v10.Value == p3 then
				return v10;
			end;
		end;
		return false;
	end;
	local function u5()
		local v11 = {};
		for v12, v13 in pairs(u3()) do
			if not u4(v13) then
				table.insert(v11, v13);
			end;
		end;
		return v11;
	end;
	local function u6(p4)
		for v14, v15 in pairs(p1:GetChildren()) do
			if v15.Value == p4 then
				return true;
			end;
		end;
		return false;
	end;
	local function u7(p5)
		for v16, v17 in pairs(p1:GetChildren()) do
			if v17.Value == p5 then
				v17.Value = nil;
				if p2 then
					for v18, v19 in pairs(u5()) do
						v19.Parent = script;
						v19.Parent = u1;
					end;
				end;
				return true;
			end;
		end;
		return false;
	end;
	local function v20(p6)
		if not p6:IsA("Tool") then
			return nil;
		end;
		if u6(p6) then
			return true;
		end;
		p6.AncestryChanged:Connect(function()
			if p6.Parent ~= l__Character__2 and p6.Parent ~= u1 then
				u7(p6);
			end;
		end);
		for v21, v22 in pairs(p1:GetChildren()) do
			if v22.Value == nil then
				v22.Value = p6;
				if p6.Parent == l__Character__2 then
					v3.Value = v22;
				end;
				return true;
			end;
		end;
		return false;
	end;
	for v23, v24 in pairs(u1:GetChildren()) do
		v20(v24);
	end;
	u1.ChildAdded:Connect(v20);
	for v25, v26 in pairs(l__Character__2:GetChildren()) do
		v20(v26);
	end;
	l__Character__2.ChildAdded:Connect(v20);
	local function u8(p7)
		for v27, v28 in pairs(l__Character__2:GetChildren()) do
			if v28:IsA("Tool") then
				v28.Parent = u1;
			end;
		end;
		if p7 then
			p7.Parent = l__Character__2;
			p7.Unequipped:connect(function()
				wait();
				v3.Value = u4(l__Character__2:FindFirstChildOfClass("Tool"));
			end);
		end;
		if p7 == nil then
			v3.Value = nil;
		end;
	end;
	v3.Changed:Connect(function()
		local l__Value__29 = v3.Value;
		if not l__Value__29 then
			u8(nil);
			return;
		end;
		u8(l__Value__29.Value);
	end);
	for v30, v31 in pairs(p1:GetChildren()) do
		v31.Changed:connect(function()
			if v3.Value == v31 then
				wait();
				u8(v31.Value);
			end;
		end);
	end;
	local function u9(p8)
		p8 = tostring(p8);
		local v32 = string.split(p8, ".");
		return v32[#v32];
	end;
	l__UserInputService__1.InputBegan:Connect(function(p9, p10)
		if not p10 and p9.UserInputType == Enum.UserInputType.Keyboard then
			local v33 = p1:FindFirstChild((u9(p9.KeyCode)));
			if v33 then
				if v3.Value == v33 then
					v3.Value = nil;
					return;
				end;
				v3.Value = v33;
			end;
		end;
	end);
	return v3;
end;

1 Like

Anyone?? I could really use the help on this

Someone help I’m willing to send a copy of the system, so you can understand… notable people only though I’m not sending it to someone who doesn’t have scripting experience

I realllyyyy need the help, this will shape my gameplay a lot.

The code is very hard to understand. Also having trouble understanding what the problem is. You are providing scripts for the backpack but you are saying the tool is broken?

The tool I’m using, is a model not an actual tool, the scripts originally provided, allowed me to utilize the model as a tool in my backpack. But when I transfer over the system to my backback gui it’s breaks and doesn’t accept the model as a tool.

MAIN INVENTORY SCRIPT, may help someone understand. So basically I just want this to put the model from Tools into the player backpack without it having to be a “tool”. Im using a model instead that is animated.

--// datastore things // Adding/Removing Items from Inv Data

local HttpService = game:GetService("HttpService")
local events = game.ReplicatedStorage.InvEvents


game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		if not game.ServerStorage.Inventories:FindFirstChild(player.Name.."Inventory") then
	        local invFolder = Instance.new("Folder", game.ServerStorage.Inventories)
			invFolder.Name = player.Name..'Inventory' -- Ex: BobInventory
			print('Unique Folder Added To Inventory: ServerStorage')
			
			
			--// Let's load any data we may have
			local InvStat = player:WaitForChild("Data_Folder").InvData
			
			if InvStat.Value ~= '' then
				--// Now Lets replicate to our Folder
				
				local LoadedData = HttpService:JSONDecode(InvStat.Value)
				
				for i, x in pairs(LoadedData[1]) do
					if x then
						local newString = Instance.new("StringValue", invFolder)
						newString.Name = tostring(x)
					end
				end
				
			
				--// now lets send this data to the server
				events.LoadData:FireClient(player, LoadedData)
				
				
			end
			
			
		end
    end)
end)

events.AddToInv.OnServerEvent:Connect(function(player, item)
	
	local debounce = false
	
	if debounce == false then
		debounce = true
		local current = player:FindFirstChild("Data_Folder").CurrentStorage
		current.Value += 1
		
		local toInv = Instance.new("StringValue")
		toInv.Parent = game.ServerStorage.Inventories:FindFirstChild(player.Name.."Inventory")
		toInv.Name = tostring(item)

		print('Added To Inventory! Item: '..item)
		
		task.wait(0.5)
		
		--//Saving
		local playerData = game.ServerStorage.Inventories:FindFirstChild(player.Name.."Inventory")
		local InvStat = player:FindFirstChild("Data_Folder").InvData
		if InvStat and playerData then
			print('Found Player Inventory: ServerStorage (Attempting Save)')
			local Contents = {}
			
			for i, itemdata in pairs (playerData:GetChildren()) do
				table.insert(Contents, itemdata.Name)
		
			end

			task.wait()
			
			
			local ToSave = {Contents}
			
	
			local FinalSaveData = HttpService:JSONEncode(ToSave) -- Save the data
			InvStat.Value =  FinalSaveData
			
	
	
		end
		
		
		debounce = false

	end

end)

events.RemoveFromInv.OnServerEvent:Connect(function(player, item)
	local debounce = false
    print('called event')
	if debounce == false then
		debounce = true
		local current = player:FindFirstChild("Data_Folder").CurrentStorage
		current.Value -= 1 

		local inv = game.ServerStorage.Inventories:FindFirstChild(player.Name.."Inventory")
		inv:FindFirstChild(item):Destroy() 
		

		print('Removed From Inventory! Item: '..item)

		task.wait(0.5)

		--//Saving
		local playerData = game.ServerStorage.Inventories:FindFirstChild(player.Name.."Inventory")
		local InvStat = player:FindFirstChild("Data_Folder").InvData
		if InvStat and playerData then
			print('Found Player Inventory: ServerStorage (Attempting Save)')
			local Contents = {}

			for i, itemdata in pairs (playerData:GetChildren()) do
				table.insert(Contents, itemdata.Name)		
			end

			task.wait()


			local ToSave = {Contents}


			local FinalSaveData = HttpService:JSONEncode(ToSave) -- Save the data
			InvStat.Value =  FinalSaveData



		end
		debounce = false

	end
end)

game.ReplicatedStorage.InvEvents.ObjectGive.OnServerEvent:Connect(function(player, item, priority)
	--// Priority can be Primary, Secondary, or Other \\ Tool.Priority is dif.
	local backpack = player.Backpack
	local char = player.Character
	
	for i, x in pairs(backpack:GetChildren()) do
		if x:FindFirstChild("Priority") and  x:FindFirstChild("Priority").Value ~= ''  then -- say it was Primary (only 1 Primary can exist)
			if x:FindFirstChild("Priority").Value == tostring(priority) then
			   x:Destroy()
			end
		else
		end
	end
	

	for i, x in pairs(char:GetChildren()) do
		if x:FindFirstChild("Priority") and  x:FindFirstChild("Priority").Value ~= ''  then -- say it was Primary (only 1 Primary can exist)
			if x:FindFirstChild("Priority").Value == tostring(priority) then
			   x:Destroy()
			end
		else
		end
	end
	
	
	if item ~= nil then -- meaning player is not removing an item

		
		local giveTool = game.ReplicatedStorage.Tools:FindFirstChild(tostring(item)):Clone()
		giveTool.Priority.Value = priority
		giveTool.Parent = backpack
	elseif item == nil then
		print('No Item, just Removing')
		
	end
end)

This code is what is actually used to accept players items and move it into their backpack. The backpack is the original code posted which I need it to accept models.

	if item ~= nil then -- meaning player is not removing an item

		
		local giveTool = game.ReplicatedStorage.Tools:FindFirstChild(tostring(item)):Clone()
		giveTool.Priority.Value = priority
		giveTool.Parent = backpack
	elseif item == nil then
		print('No Item, just Removing')
		
	end
end)

If anyone can help pleasee…
Advanced Melee System with inventory helpppp1.rbxl (679.9 KB)
heres the whole game since its been a challenge getting help, if someone could fix it that would be very helpful thank you! Ive been trying for days now to get this to work appropriately so I can move forward.

Update: I fixed my issue with the model not submitting to my backpack… It now goes in my backpack but now wont run the AMS scripts someone pleaseee help me…
Advanced Melee System with inventory helpppp2.rbxl (670.4 KB)

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