Как сделать систему рандомного выбора товара для покупателя(Roblox Studio)
У меня есть покупатель, он должен рандомно выбрать 1 из товаров и пойти к полке(выбирает 1 товар из модельки с местоположением точек куда он придет(полка с товаром) если выпадет этот товар). Проблема возникает в том, что у меня никаким образом не получается получить объект из модельки по индексу, а других вариантов для решения этой задачи я не знаю. Проблем с передвижением до полки нет. Вот код:
local SimplePath = require(game:GetService("ServerStorage").SimplePath)
local Rig = script.Parent
local Kill = workspace.Kill
local MoneyBuy = 0
local Buy = workspace.Buy
local IsBuy = false
local Buying = script.Parent.ProximityPrompt
local ItemsList = game.Workspace.ItemsForBuy
local ItemsCount = #ItemsList:GetChildren()
local ItemForBuy = math.random(0, ItemsCount)
local i = 1
local a = 0
while a ~= ItemForBuy do
a = ItemsList:GetChildren().Value[i]
if (a == ItemForBuy) then
ItemForBuy = ItemsList:GetChildren()[i]
end
i += 1
end
local ItemGrab = SimplePath.new(Rig)
local BuyPath = SimplePath.new(Rig)
local KillPath = SimplePath.new(Rig)
print(ItemForBuy)
ItemGrab:Run(ItemForBuy)
ItemGrab.Reached:Connect(function()
BuyPath:Run(Buy)
MoneyBuy += ItemForBuy.Price.Value
end)
BuyPath.Reached:Connect(function()
local i = 0
while (IsBuy == false and i < 20) do wait(1) i += 1 end
_G.money += MoneyBuy
KillPath:Run(Kill)
end)
KillPath.Reached:Connect(function()
script.Parent.Humanoid.Health = 0
end)
Buying.Triggered:Connect(function()
IsBuy = true
end)
Скрипт Money состоит только из строки: _G.money = 0