Ask for help on my Script

Hello guys i’m yeildingsavage23 and making an inventory system and i got a problem when i cloning the item like this

button.MouseButton1Down:Connect(function()
local item = item
remote:FireServer(item)
end)

and

remote.OnServerEvent:Connect(function(player , item)
local newitem = item:Clone()
newitem.Parent = char
end)

then i got error saying the newitem is nil i dont know why plss someone help me

Inside your LocalScript, what exactly is “item”? It seems that it may be nil, or not be a Cloneable Instance.

1 Like

Its a tool and its cloneable i already clone the tool before

Where is the item variable though? Could you give us a larger version of the script? It looks like you were just placing down random names there.

the script i make on my post is just example i have a lot of codes

The problem might be with how you said “item = item”. When you have both variables named the same, it’s likely messing up the script.

Try changing this to:

button.MouseButton1Down:Connect(function()
local myItem = item
remote:FireServer(myItem)
end)

and

also change this to:

remote.OnServerEvent:Connect(function(player , myItem)
local newitem = myItem:Clone()
newitem.Parent = char
end)

Yeah, but where do you define item? Is it a table or just some tool?

here my codes and sorry for make the variable not named properly :slight_smile:

here the code of the local script


local inventory = script.Parent
local abilitiesHolder = inventory:WaitForChild("abilitiesHolder")
local Itemholder = inventory:WaitForChild("Itemholder")
local Abilities = abilitiesHolder:WaitForChild("Abilities")
local Damage = Abilities:WaitForChild("Damage") 
local Speed = Abilities:WaitForChild("Speed") 
local Crit = Abilities:WaitForChild("Crit")
local Equip = abilitiesHolder:WaitForChild("Equip")
local Rarity = abilitiesHolder:WaitForChild("Rarity")
local ViewPort = Rarity:WaitForChild("ViewPort")
local NameOfItem = Rarity:WaitForChild("NameOfItem")
local Scrolling = Itemholder:WaitForChild("Scrolling")
local RarityHolder = Scrolling:WaitForChild("RarityHolder")

local Design = RarityHolder:WaitForChild("Design")

local ItemHolder = Design:WaitForChild("ItemHolder")
local itemname = Design:WaitForChild("itemname")

local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = player.Character or player.CharacterAdded:Wait()
--local tools = player.StarterGear:GetChildren()
local tools = player.Backpack:GetChildren()

local replicated = game:GetService("ReplicatedStorage")
local folder = replicated:WaitForChild("remotes")
local inventoryremote = folder:WaitForChild("inventorysystem")
local eqiupsystem = folder:WaitForChild("EquipSystem")

for i,v in pairs(tools) do
	warn(v.Name)

	local itemframe = RarityHolder:Clone()
	itemframe.Name = v.Name
	itemframe.Parent = Scrolling
	itemframe.Design.itemname.Text = v.Name
	itemframe.Visible = true
	itemframe.Design.ItemHolder.Image = v.TextureId
	
	local testitem = v:Clone()
	testitem.Parent = itemframe.Design.ItemHolder
	
	itemframe.ImageColor3 = testitem:WaitForChild("ColorValue").Value
	itemframe.Design.ImageColor3 = testitem:WaitForChild("DesignColor").Value
	
	itemframe.Design.itemname.MouseButton1Down:Connect(function()
		local clickCD = false
		if clickCD == false then
			clickCD = true
				local usingitem = itemframe.Design.ItemHolder:FindFirstChildWhichIsA("Tool"):Clone()
				NameOfItem.Text = usingitem.Name
				ViewPort.Image = usingitem.TextureId
				eqiupsystem:FireServer(usingitem)
				wait(2)
			clickCD = false
		end
	end)
	
	
	
--[[	Equip.MouseButton1Down:Connect(function()
		local equipCD = false
		if equipCD == false then
			equipCD = true
			local theItem = ViewPort:FindFirstChildWhichIsA("Tool")
			warn(theItem.Name)
				inventoryremote:FireServer(theItem)
				wait(2)
			equipCD = false
		end
	end)
	
]]

end

and heres the script im so sorry for making my code you know messy


local replicated = game:GetService("ReplicatedStorage")
local folder = replicated:WaitForChild("remotes")
local eqiupsystem = folder:WaitForChild("EquipSystem")

eqiupsystem.OnServerEvent:Connect(function(player , item)
	local char = player.Character
	local newitem = item:Clone()
	newitem.Parent = char
end)

What might also work, is just don’t include “local item = item”. There’s no need for that. Just get rid of that line where you say it.

sorry for not telling the code on my post is just example

Before trying what I said in my longer reply, try just removing “local item = item”. Let me know if it works. If not, try my longer reply.

itemframe.Design.itemname.MouseButton1Down:Connect(function()
		local clickCD = false
		if clickCD == false then
			clickCD = true
				local usingitem = itemframe.Design.ItemHolder:FindFirstChildWhichIsA("Tool"):Clone() -- here the item variable
				NameOfItem.Text = usingitem.Name
				ViewPort.Image = usingitem.TextureId
				eqiupsystem:FireServer(usingitem)
				wait(2)
			clickCD = false
		end
	end)

Here you send “usingitem” to the server…

But then here you’re bringing in “item”.

Try changing the script to this:

local replicated = game:GetService("ReplicatedStorage")
local folder = replicated:WaitForChild("remotes")
local eqiupsystem = folder:WaitForChild("EquipSystem")

eqiupsystem.OnServerEvent:Connect(function(player , usingitem)
	local char = player.Character
	local newitem = usingitem:Clone()
	newitem.Parent = char
end)

its still nil so now im making a new button to try

and the new button i make is still not working i put the new code with cloning the tool

local remote = game.ReplicatedStorage.RemoteEvent

script.Parent.MouseButton1Click:Connect(function()
	local item = script.Parent:FindFirstAncestorWhichIsA("Tool")
	remote:FireServer(item)
end)

i use the findfirstchildwhichisa bcuz i need to use it on my real code and here the remote

local remote = game.ReplicatedStorage.RemoteEvent

remote.OnServerEvent:Connect(function(player , item)
	local char = player.Character
	local newitem = item:Clone()
	newitem.Parent = char
end)

heres the images

In the screenshots you sent me, it looks like you used “FindFirstAncestorWhichIsA”, not “FindFirstChildWhichIsA”. But perhaps that was a typo by you.

1 Like

Thank you so much its work but can you help me again how i make it filtering enable the script i know now why i got an error thats bcuz its not filtering enable i tried to make is the line of for i,v in pairs() do

this code

i know how to use remote event but on this case its just under the for i,v in pairs()??

1 Like

To enable/disable filtering enable, I believe you have to click on “Workspace” in the explorer, and then go to properties.

And am I glad I could help with that!