So from this I wanna be able to find out what’s next from this list, which in this case would be Number 1, Depth 2. And then once the player has Depth 3 for Number 1, it would move onto Number 2, Depth 1
when your invoking the server you wold need to pass along the current number and depth , and then you can do this:
local PlayersTail,PlayersDepth = CheckTail:InvokeServer(currentTail,currentDepth)
--then on the server you do this when the remote function is invoke
Tails = {
{Number = 1, Depth = 1, Cost = 0},
{Number = 1, Depth = 2, Cost = 50},
{Number = 1, Depth = 3, Cost = 100},
{Number = 2, Depth = 1, Cost = 250},
{Number = 2, Depth = 2, Cost = 500},
{Number = 2, Depth = 3, Cost = 1000},
}
local function GetNextTailInfo(player,currentTail,currentDepth)
for index,tailInfo in pairs(Tails) do
if tailInfo["Number"] == currentTail and tailInfo["Depth"] == currentDepth then
return Tails[index+1]["Number"], Tails[index+1]["Depth"]
end
end
end
CheckTail.OnServerInvoke = GetNextTailInfo
--post Edited***
--warning there may be some syntax errors i did this online
no it doesnt i though you wanted to sorry you can just do this on the client then:
Tails = {
{Number = 1, Depth = 1, Cost = 0},
{Number = 1, Depth = 2, Cost = 50},
{Number = 1, Depth = 3, Cost = 100},
{Number = 2, Depth = 1, Cost = 250},
{Number = 2, Depth = 2, Cost = 500},
{Number = 2, Depth = 3, Cost = 1000},
}
local function GetNextTailInfo(currentTail,currentDepth)
for index,tailInfo in pairs(Tails) do
if tailInfo["Number"] == currentTail and tailInfo["Depth"] == currentDepth then
return Tails[index+1]
end
end
end
--in thefunction above you just pass the currentTail and currentDepth to get the next one
--this function would return the table of information so you would use it like this
local currentTail,currentDepth = 1,1 -- just an example
local nextInfo = GetNextTailInfo(currentTail,currentDepth)
print(nextInfo["Number"],nextInfo["Depth"],nextInfo["Cost"]
local PlayersTail, PlayersDepth = CheckTail:InvokeServer()
local NextTail = GetNextTailInfo(PlayersTail, PlayersDepth)
print('Before', NextTail.Number, NextTail.Depth) -- Prints 1, 2 (correct)
local function GetNextTailInfo(tail, depth)
for i, v in pairs(PurchaseData.Tails) do
if v['Number'] == tail and v['Depth'] == depth then
return PurchaseData.Tails[i + 1]
end
end
end
if BuyTail:InvokeServer() then
PlayersTail, PlayersDepth = CheckTail:InvokeServer()
NextTail = GetNextTailInfo(PlayersTail, PlayersDepth)
print('Buying', NextTail.Number, NextTail.Depth) -- attempt to call nil value
end
local PlayersTail, PlayersDepth = CheckTail:InvokeServer()
local function GetNextTailInfo(tail, depth)
for i, v in pairs(PurchaseData.Tails) do
if v['Number'] == tail and v['Depth'] == depth then
return PurchaseData.Tails[i + 1]
end
end
end
local NextTail = GetNextTailInfo(PlayersTail, PlayersDepth)
print('Before', NextTail.Number, NextTail.Depth) -- Prints 1, 2 (correct)
if BuyTail:InvokeServer() then
PlayersTail, PlayersDepth = CheckTail:InvokeServer()
NextTail = GetNextTailInfo(PlayersTail, PlayersDepth)
print('Buying', NextTail.Number, NextTail.Depth) -- attempt to call nil value
end
function BuyTail.OnServerInvoke(player)
local User = PlayerData[player.UserId]
if not User then return end
local NextTail
for i, v in pairs(PurchaseData.Tails) do
if v['Number'] == User.Tail and v['Depth'] == User.Depth then
NextTail = PurchaseData.Tails[i + 1]
end
end
if User.Pearls >= NextTail.Cost then
UpdatePearls(player, -NextTail.Cost, false)
User.Tail = NextTail
DataUpdated:FireClient(player, User)
return true
else
return false
end
end