So, I’m making a round based survival with an objective, the first team’s objective is to collect all items and escape.
so i implemented the items, only i did it the ghetto way and now items don’t remove themselves properly from the table as seen here below.
as you see in this video, the number doesn’t drop below 3 initially and once i collect all of the nodes, it’s still not zero, this varies each play test, so i can somehow collect all 4 but not the one.
I don’t know what’s the cause of it, could you help out?
This is how each player receives nodes, server gives each player 5 of those:
function Handler:GetEachScientistAnItem()
local nodes = {}
local runningMap = workspace:FindFirstChild(MapList[MapIndex])
if runningMap then
local Nodes = runningMap.Nodes:GetChildren()
local Scientists = T.Scientist:GetPlayers()
for index, node in pairs(Nodes) do
table.insert(nodes, Nodes[index])
end
for i = 1, #Scientists do
local playerNodes = {}
for j = 1, 5 do
local randomIndex = math.random(#nodes)
table.insert(playerNodes, nodes[randomIndex])
table.remove(nodes, randomIndex)
print(nodes)
end
Remotes.GiveEachAnItem:FireClient(Scientists[i], playerNodes)
end
print(nodes)
end
end
and this is how client handles those nodes, keep in mind each set of nodes for each player is unique so only the player who received them can collect them:
function updateCount(number)
Core.Parent.Collect.Text = number
end
function FindItems(Table: {any})
local Saved = Table
print("hey look what server gave me:")
print(Saved)
for index, thing: BasePart in pairs(Saved) do
thing.Color = Color3.fromRGB(math.random(0, 255), math.random(0, 255), math.random(0, 255))
thing.Touched:Connect(function()
table.remove(Saved, index)
updateCount(#Saved)
print(Saved)
thing:Destroy()
end)
end
end
Remotes.GiveEachAnItem.OnClientEvent:Connect(FindItems)