Values in Gui are Nil when passed through Remote event

Hey you all. Right now I’m developing an obby game with a round system, and I’m working on the shop system right now. I am working on the tool section of the shop, but there has been an error. For some reason, when I try to pass data (Such as the price, amount of that item you have, etc.) into a remote function to tell the server to update the player’s stats, it will error and say that those values are nil. These values are the ones that you can put into the explorer, and when I pass the value of it (for example, price.Value) it works. But if I try to use price.Value in the remote event’s receiver, It will error and say word for word: ServerScriptService.ShopManagement.PurchaseManagement:6: attempt to index nil with ‘Value’

Also, this was working completely fine until I found out that I wasn’t cloning the frame that is supposed to be duplicated into the scrolling frame. After I cloned it in the LoadToolsModule script, this started happening.

I have tried looking throughout the dev forums, nothing showed up. I’ve had no luck in finding the cause of the problem. Maybe I’m just missing something obvious, but I’m not sure.

Here is the explorer:

Here is the LoadToolsModule script:

local module = {}


function module.loadItems(ItemFolder)
	
	--Variables
	local MainFrame = script.Parent.Parent
	local ToolsShop = MainFrame:WaitForChild("ToolsShop")
	local Frames = ToolsShop:WaitForChild("Frames")
	
	local toolsScrollingFrame = ToolsShop:WaitForChild("ScrollingFrame")
	
	
	--Check if item is round or keep
	if ItemFolder.Parent.Name == "Round" then
		
		--Round items
		for i, tool in pairs(ItemFolder:GetChildren()) do
			
			--Variables
			local info = tool:WaitForChild("Info")
			local price = info:WaitForChild("Price")
			local currentCount = info:WaitForChild("CurrentCount")
			local name = info:WaitForChild("Name")
			
			
			local toolFrame = Frames:WaitForChild("RoundFrame"):Clone()
			toolFrame.Parent = toolsScrollingFrame
			
			local toolValues = toolFrame:WaitForChild("Values")
			local toolCurrentCount = toolValues:WaitForChild("CurrentCount")
			local toolPrice = toolValues:WaitForChild("Price")
			local toolName = toolValues:WaitForChild("Name")
			
			
			--Make sure to handle currentCount Value later!!
			toolPrice.Value = price.Value
			toolName.Value = name.Value
			
			toolFrame.Visible = true
			
			
		end
		
		
	elseif ItemFolder.Parent.Name == "Keep" then
		
		--Keep items
		print("keep")
		
	end
	
end


return module

ToolFunctionModule (Where the remote event is fired):

local module = {}

function module.toolFunctions(plr)
	
	--Variables
	local plrCash = plr:WaitForChild("leaderstats"):WaitForChild("Cash")

	local purchaseEvent = game:WaitForChild("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("PurchaseEvent")

	local MainFrame = script.Parent.Parent
	local ToolsShop = MainFrame:WaitForChild("ToolsShop")

	local ToolScrollingFrame = ToolsShop:WaitForChild("ScrollingFrame")

	local ToolsList = {}
	for i, v in pairs(ToolScrollingFrame:GetChildren()) do
		if v:IsA("Frame") then
			table.insert(ToolsList, v)
		end
	end



	--Load Tools
	for i, buyFrame in pairs(ToolsList) do

		--Variables
		local viewport = buyFrame:WaitForChild("ViewportFrame")
		local purchaseButton = buyFrame:WaitForChild("PurchaseButton")
		local valuesFolder = buyFrame:WaitForChild("Values")

		local price = valuesFolder:WaitForChild("Price")
		local currentCount = valuesFolder:WaitForChild("CurrentCount")
		local name = valuesFolder:WaitForChild("Name")
		
		
		purchaseButton.MouseButton1Click:Connect(function()
			
			if plrCash.Value >= price.Value then

				purchaseEvent:FireServer(price, currentCount, plrCash, name)

			else

				print("Cannot afford item")

			end

		end)

	end
	
end

return module

PurchaseManagement (Where the remote event errors)

--Variables
local purchaseEvent = game:WaitForChild("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("PurchaseEvent")

purchaseEvent.OnServerEvent:Connect(function(plr, price, currentCount, plrCash, name)
	
	print(price.Value)
	
	plr:WaitForChild("leaderstats"):WaitForChild("Cash").Value = plr:WaitForChild("leaderstats"):WaitForChild("Cash").Value - price.Value

	print(price.Value)

	--Add to inventory
	currentCount.Value += 1

	print(currentCount.Value)
	
	
	--MAKE SURE TO REMOVE WHEN INVENTORY SYSTEM IS ADDED!!
	local tool = game:WaitForChild("ReplicatedStorage"):WaitForChild("ShopItems"):WaitForChild("StandardItems"):WaitForChild("Round"):WaitForChild("Tools"):WaitForChild(name.Value):Clone()
	tool.Parent = plr:WaitForChild("Backpack")
	
	
end)

LoadItemsScript (Basically just used for calling the remote functions from previous module scripts):

--Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--Modules
local LoadToolsModule = require(script:WaitForChild("LoadToolsModule"))
local ToolFunctionModule = require(script:WaitForChild("ToolFunctionModule"))

--Variables
local plr = game:GetService("Players").LocalPlayer


local ShopItems = ReplicatedStorage:WaitForChild("ShopItems")

local StandardItems = ShopItems:WaitForChild("StandardItems")
local KeepStandardItems = StandardItems:WaitForChild("Keep")
local RoundStandardItems = StandardItems:WaitForChild("Round")

local StandardRoundTools = RoundStandardItems:WaitForChild("Tools")

local GamepassItems = ShopItems:WaitForChild("GamepassItems")



LoadToolsModule.loadItems(StandardRoundTools)
ToolFunctionModule.toolFunctions(plr)

Thank you all for helping out! :happy2:

2 Likes

Also by the way, I found out to clone the frame into the scrolling frame in the LoadToolsModule script.
Here is the exact line of code for that, which you can find in the original post:

local toolFrame = Frames:WaitForChild("RoundFrame"):Clone()
1 Like

What if instead of passing the Value Object, you just pass the Value itself
like this:

purchaseEvent:FireServer(price.Value, ect)
1 Like

I tried that, but if I do that then I only modify the variables value, not the actual object’s value. If I passed currentCount.Value for example, I would only be modifying the variable in the remote event, not the actual object’s value in explorer

In the reply above mine you are cloning a frame locally which I assume has the values in it. Since that clone is local, those values and everything else in it are not replicated to the server, meaning it doesn’t exist so the server has no value to change.

If you’re trying to get a purchase system going, I would recommend handling the if statement on the server side. Find the player’s cash and have the price of each item stored somewhere. You can then fire the item that the player wants to purchase so the server can check for its price and the player’s cash. If you are sending the price and cash from the client, an exploiter can manipulate them.

So would I replicate the Gui updates to each player from the server? And im guessing I should put the items and stuff in serverStorage

Yeah, handling all backend stuff on the server is the best practice.

Could you give a quick example, because I’m kinda confused on how to actually do that. Im guessing you create a remote event for when the player presses the purchase button, and then do all of the price and counting stuff on the server?

Sure, this might not be the best way but I hope you get the idea.

Local Script

purchaseButton.MouseButton1Click:Connect(function()
      RemoteEvent:FireServer(name) --somehow have the name of the item
end)

Server Script

local prices = {
 ["item1"] = 10,
 ["item2"] = 20
}

RemoteEvent.OnServerEvent:Connect(function(player, nameOfItem)
        local leaderstats = player:FindFirstChild("leaderstats")
        local cashValue = leaderstats.cashValue
        local price = prices[name] --gets the price from the dictionary
        if cashValue.Value >= price then
             --handle purchase
        else
             print("not enough money")
        end
end)
1 Like

Alright, this gives me a good idea of what to do, thanks

1 Like

(Closed Question) (Nevermind, I just made a simple mistake in coding) By the way, can you pass dictionaries from the server to the client?

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