How to get only certain values from a module

Hello! I need the script to retrieve from the module only values ​​that are “Class = and here is the name of some store”

That is, if, for example, I need values ​​for a regular store, it should only get [1,2,3] from the module

--Module
local Items = {
	[1] = {NameIt = "Money Per Click", Cost = 1, Info = "test1", Limit = 1000, Class = "BasicShop", PositionCFrame = CFrame.new(28.9639988, 1.69099998, 9.8030014, 0, 0, -1, 0, 1, 0, 1, 0, 0)},
	[2] = {NameIt = "Cooldown", Cost = 1 , Info = "test2", Limit = 1000, Class = "BasicShop", PositionCFrame = CFrame.new(28.9639988, 1.69099998, 14.791, 0, 0, -1, 0, 1, 0, 1, 0, 0)},
	[3] = {NameIt = "Test", Cost = 1, Info = "test3", Limit = 1000, Class = "BasicShop", PositionCFrame = CFrame.new(28.9639988, 1.69099998, 19.661, 0, 0, -1, 0, 1, 0, 1, 0, 0)},
}

return Items
--Local script
local Curret = script.Parent.Curret
local ShopForNow = script.Parent.ShopPicked
local Player = game.Players.LocalPlayer
local Camera = game.Workspace.CurrentCamera

local InfoSc = script.Parent.InfoFrame.ScrollingFrame 

local MoneyLib = require(RS:WaitForChild("Modules"):WaitForChild("MoneyLib"))

local Items = require(RS.Modules.Shops.Items)

ButtonL.MouseButton1Click:Connect(function()
	if Curret.Value == 1 then
		Camera.CameraType = Enum.CameraType.Scriptable
		Curret.Value = math.max() --here i need to get these values
		Camera.CFrame = Items[Curret.Value].PositionCFrame
		
		InfoSc.Cost.Text = "Cost: $" ..MoneyLib.DealWithPoints(Items[Curret.Value].Cost)
		InfoSc.Info.Text =  Items[Curret.Value].Info
		InfoSc.NameItem.Text = Items[Curret.Value].NameIt
		
	else
		Curret.Value -= 1 
		Camera.CameraType = Enum.CameraType.Scriptable
		Camera.CFrame = Items[Curret.Value].PositionCFrame
		
		InfoSc.Cost.Text = "Cost: $" ..MoneyLib.DealWithPoints(Items[Curret.Value].Cost)
		InfoSc.Info.Text =  Items[Curret.Value].Info
		InfoSc.NameItem.Text = Items[Curret.Value].NameIt
		
	end
end)

I do not know how to do that. Anyone have any ideas?

(I don’t know how to get all the values ​​and search by [Class] only the values ​​that are ShopForNow.Value)

Then, you can do Items[1] and it should be the same as:

local Items = require(RS.Modules.Shops.Items)
local ValidItems = {}

for i,v in next, Items do 
    if v.Class == "BasicShop" --[[ShopForNow.Value will work here]] then
        table.insert(ValidItems, v)
    end
end

-- do whatever here

ValidItems is the table of items of that class.

1 Like

Can you tell how to make math.max correctly?

math.max(ValidItems,ValidItems) --not working or math.max(ValidItems) too not working

Answer:

--...

--I'm using function Button.MouseButton1Click:Connect(function()
local ValidItems = {}

for i,v in next, Items do 
    if v.Class == "BasicShop" --[[ShopForNow.Value will work here]] then
        table.insert(ValidItems, i)
    end
end

math.min(table.unpack(ValidItems)) or math.max(table.unpack(ValidItems)

--Ex:

if Curret.Value == math.min(table.unpack(ValidItems)) then
		Camera.CameraType = Enum.CameraType.Scriptable
		Curret.Value = math.max(table.unpack(ValidItems))
		Camera.CFrame = Items[Curret.Value].PositionCFrame
	--...

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