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!