Inventory Gui not working

Hi Developers! My achieve is to when theres wood, and you can grab them by clicking them, so the script detects so the player gives the wood from inventory so I need to work it out.

I want to make it work, I have too much solutions but I havent found out yet.

Server Script:

local InventoryEvents = game:GetService("ReplicatedStorage").InventoryEvents
local ItemResources = game:GetService("ServerStorage").ItemResources

InventoryEvents.SpawnItem.OnServerEvent:Connect(function(player, character, resource_Name : string)
	if ItemResources:FindFirstChild(resource_Name) then
		local item : BasePart = ItemResources:FindFirstChild(resource_Name):Clone()
		local Click = Instance.new("ClickDetector")
		
		item.Parent = workspace
		item.CFrame = character:FindFirstChild("HumanoidRootPart").CFrame * CFrame.new(0,0, -2.5)
		
		Click.Parent = item
		Click.MouseClick:Connect(function()
			InventoryEvents.client.addInvButton:FireClient(player, item.Name, ItemResources:FindFirstChild(resource_Name):FindFirstChild("Description").Value, resource_Name, 1)
			item:Destroy()
		end)
		
		Click.MaxActivationDistance = 18
	else
		warn(resource_Name.." is not valid item for resources.")
	end
end)

InventoryEvents.client.GetDescriptionFromResource.OnServerInvoke = function(ResourceName)
	if ItemResources:FindFirstChild(ResourceName) then
		local resource = ItemResources:FindFirstChild(ResourceName)
		
		if resource:FindFirstChild("Description") then
			local desc = resource:FindFirstChild("Description")
			
			return desc.Value
		end
	end
end

Local Script: (from InventoryGui)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local GridLayout = script.Parent.HeadFrame.GridLayout
local Properties = script.Parent.HeadFrame.Properties

--- Script Properties / Gui Values
local currentlyUsed = {
	resourceName = "",
	buttonName = "",
	resourceRemaining = 0
}

--ReplicatedStorage.InventoryEvents.SpawnItem:FireServer(game.Players.LocalPlayer.Character, "Wood")

if script.Parent.HeadFrame.Visible then script.Parent.HeadFrame.Visible = false end

local function refreshButtonAppearance()
	task.spawn(function()
		for i,v in pairs(GridLayout:GetChildren()) do
			if v.ClassName == "TextButton" then
				local v2 : TextButton = v
				v2.BackgroundColor3 = Color3.new(1,1,1)
				
				currentlyUsed.resourceName = ""
				currentlyUsed.buttonName = ""
				currentlyUsed.resourceRemaining = 0
			end
		end
	end)
end

local function setInvButtonFunctional(instance : TextButton, Desc : string, Name : string, ResourceName, items)
	instance.MouseButton1Click:Connect(function()
		refreshButtonAppearance()
		task.wait()
		instance.BackgroundColor3 = Color3.new(0,.7,0)
		
		Properties.NameTxt.Text = Name
		Properties.DescriptionTxt.Text = Desc
		Properties.ItemCount.Text = tostring(items.Value)
		
		currentlyUsed.buttonName = Name
		currentlyUsed.resourceName = ResourceName
		currentlyUsed.resourceRemaining = items.Value
	end)
	
	Properties.Drop.MouseButton1Click:Connect(function()
		if currentlyUsed.resourceName == ResourceName then
			if items.Value >= 1 then
				ReplicatedStorage.InventoryEvents.SpawnItem:FireServer(game.Players.LocalPlayer.Character, ResourceName)
				items.Value -= 1
			end
		end
	end)
	
	items.Changed:Connect(function()
		if currentlyUsed.resourceName == ResourceName then
			Properties.ItemCount.Text = items.Value
		end
	end)
end

local function addInvButton(Name, ResourceName, ItemCount)
	local instance = Instance.new("TextButton")
	local ResourceName = ReplicatedStorage.InventoryEvents.client.GetDescriptionFromResource:InvokeServer(Name)
	
	local DescriptionVal = Instance.new("StringValue")
	DescriptionVal.Name = "Description"
	DescriptionVal.Value = ResourceName
	
	local NameVal = Instance.new("StringValue")
	NameVal.Name = "Name"
	NameVal.Value = Name
	
	local ItemCountVal = Instance.new("NumberValue")
	ItemCountVal.Name = "ItemCount"
	ItemCountVal.Value = ItemCount
	
	instance.Size = UDim2.new(.15,0,.1,0)
	instance.BorderSizePixel = 2
	instance.BackgroundColor3 = Color3.new(1,1,1)
	
	instance.Parent = GridLayout
	instance.Text = Name
	instance.TextScaled = true
	
	NameVal.Parent = instance
	DescriptionVal = instance
	ItemCountVal.Parent = instance
	setInvButtonFunctional(instance, ResourceName, Name, ResourceName, ItemCountVal)
end

ReplicatedStorage.InventoryEvents.client.addInvButton.OnClientEvent:Connect(function(Name, Description, ResourceName, ItemCount)
	if GridLayout:FindFirstChild(Name) then
		local Item = GridLayout:FindFirstChild(Name)
		Item:FindFirstChild("ItemCount").Value += ItemCount
	else
		addInvButton(Name, ResourceName, ItemCount)
	end
end)

script.Parent.SpawnWood.MouseButton1Click:Connect(function()
	ReplicatedStorage.InventoryEvents.SpawnItem:FireServer(game.Players.LocalPlayer.Character, "Wood")
end)

script.Parent.Inventory.MouseButton1Click:Connect(function()
	script.Parent.HeadFrame.Visible = not script.Parent.HeadFrame.Visible
end)

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.Q and gameProcessedEvent ~= true then
		script.Parent.HeadFrame.Visible = not script.Parent.HeadFrame.Visible
	end
end)

Explorer:

ServerStorage:
image

image
this is video from issue

	DescriptionVal.Value = ResourceName


This is full code of what error saying the code is…

Also yes it has 3 arguments, I don’t believe my own code where the error is saying.

image
This is the result, it separated on commas so I put the other words for placeholder, I’ll change it later.

If it is, I’m not sure how setting the value of something would error like this
image

1 Like

Yes. I believe that is, I’ll try seeing the error for myself, and ok.

Hmm okay, Lemme check for that…

The picture you sended from me is an from 69, so even that is String Value I trying to send a string.


This is the code of Server Script

I mean line 69 from the client script.

Try doing:

print(ResourceName)

if ResourceName ~= nil then
 DescriptionVal.Value = ResourceName
end

wrong reply
The error shows up, It need make Description has string contained.

What’s on line 39? (chaaaaarssss)


It’s from Desc, which desc is nil so It can’t deliver the string, it got nil. So the previous code was the problem.

It tried to if Description wasn’t nil but description was nil anyways so the errors comes up from the next function.


Error shows same not current, the previous one.
image