Unable to assign property Name. string expected, got nil?

Wassup everyone and welcome to this new vid… I mean post.So I’m currently working on an InventorySystem and I got this Error “Unable to assign property Name. string expected, got nil” this is the script:(line 9)

local InventoryEvent = game.ReplicatedStorage.Remotes.InventoryEvent
local itemFrame = script.Parent:FindFirstChild(“ItemsFrame”)

InventoryEvent.OnClientEvent:Connect(function(ItemName, Value)
if Value == true then

	local ItemButton = script.Parent.ItemsFrame.ItemButton:Clone()
	ItemButton.Visible = true
	ItemButton.Name = ItemName.Name
	ItemButton.Text = ItemName.Name
	ItemButton.Parent = itemFrame
	
	local equipButton = script.Parent.EquipFrame["Equip Button"]
	
		ItemButton.MouseButton1Click:Connect(function()
			script.Parent.EquipFrame.Title.Text = ItemName.Name
			script.Parent.EquipFrame.Title.Visible = true
			equipButton.Visible = true
		end)
end

end)

1 Like

This means that the itemName value isn’t being passed properly. Ensure that when firing the remote event, the item name is properly passed. Currently, it’s passing as nil.

Can we see the script where the Inventory Remote event is fired?

2 Likes

ofc:

local inventoryEvent = game.ReplicatedStorage.Remotes.InventoryEvent

game.Players.PlayerAdded:Connect(function(player)

local inventory = player:WaitForChild("Inventory")

local inventoryFrame = player.PlayerGui:WaitForChild("InventoryGui").InventoryFrame.ItemsFrame:GetChildren()

inventory.ChildAdded:Connect(function(Item)
	inventoryEvent:FireClient(player, Item.Name, true)
end)

end)

inventoryEvent.OnServerEvent:Connect(function(player, ItemName, Value, button)

 if Value == false then
		local SelectedItem = player.Inventory:FindFirstChild(ItemName)
		local backpack = player.Backpack:GetChildren()
		local stuff = player.Character:GetChildren()
		
		if #backpack == 0 and not player.Character:FindFirstChildWhichIsA("Tool") then
			button.Text = "Unequip"
			button.BackgroundColor3 = Color3.new(255,0,0)
			SelectedItem:Clone().Parent = player.Backpack
		else
			for i,v in ipairs(backpack) do
				button.Text = "Equip"
				button.BackgroundColor3 = Color3.new(0,255,0)
				v:Destroy()
			end
			for i, v in ipairs(stuff) do
				if v:IsA("Tool") then
					button.Text = "Equip"
					button.BackgroundColor3 = Color3.new(0,255,0)
					v:Destroy()
				end
			end
		end
 end

end)

pls response bro I rlly need help pls pls pls

Change the lines that say

ItemButton.Name = ItemName.Name
ItemButton.Text = ItemName.Name

to

ItemButton.Name = ItemName
ItemButton.Text = ItemName
2 Likes

thx this was the prob…um would u might if u help me fix the last error? it says

ServerScriptService.InventoryScript:24: attempt to index nil with ‘Clone’

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