I’mt trying to make a buy all script like ninja legends basically by looping through a table inside of a module and subtract the amount of money they can use to buy the items.
I’ve tried finding a devforum post but I couldn’t. Here is the code:
Module Script
local Tools = {
{Name = 'Test', Price = 5},
{Name = 'Test2', Price = 3},
{Name = 'Test3', Price = 2},
{Name = 'Test4', Price = 7},
{Name = 'Test5', Price = 6}
}
local ToolLibrary = {}
for index, object in pairs(Tools) do
object.Index = index
ToolLibrary[object.Name] = object
end
local DefaultTool = ToolLibrary.Test1 -- This is an example of the equipped tool the player has
local NextTool = Tools[DefaultTool.Index + 1] -- example of the locked tool the player has
return Tools
--------------------------------------------------------------------
Server:
local module = require(pathway.Module)
Remote.OnServerEvent:Connect(function(player)
-- How would you go about buying all the things the player can afford in order.
--Pathway to player's currency is player.leaderstats.Coins
end)
Not exactly I’m trying to loop through the returned table from the module and get the lowest price basically I’ll edit it so I can have it like that and basically I wanna use the ToolLibrary to get the index from the table and then have the player on the remote event take away the money for all they can buy and update the default tool and next tool.
Well, for starters the module script isn’t going to return the table. Module is different then module. Change the return statement to return Module because that is your table name.
Alrighty, well change the name of the table to module. Return statement won’t return the table because of the names. And please change something other than module just for the purpose.
local ToolLibrary = {}
for index, object in pairs(Tools) do
object.Index = index
ToolLibrary[object.Name] = object
end
local DefaultTool = ToolLibrary.Test1 -- This is an example of the equipped tool the player has
local NextTool = Tools[DefaultTool.Index + 1]
I can use this to get the things but like how would I do that to loop through returned table in order and start from least to highest and buy the items.
I’mt trying to make a buy all script like ninja legends basically by looping through a table inside of a module and subtract the amount of money they can use to buy the items. I can use this to get the things but like how would I do that to loop through returned table in order and start from least to highest and buy the items.