I’ve stopped scripting for a year so spare me.
When I was working with table.insert(), I though that of course, it does as it says, inserts a value given into the table.
So of course, applying what I know, I tried doing this:
queuePad.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
-- First Part
if not player then return end
if leaving[player] or queueTable[player] or #queueTable == playerLimit then return end
local charRemoving, leavingConnection
-- Second Part
table.insert(queueTable, player)
if queueTable[player] then print("Got Player") end
-- Unimportant things continuation.
The first part works as it would “expected”. However, the second part is where it was confusing me.
By doing table.insert(queueTable, player) and checking the queueTable by doing print(queueTable). It would of course show my player HOWEVER before and after:
queuePad.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
-- First Part
if not player then return end
if leaving[player] or queueTable[player] or #queueTable == playerLimit then return end
local charRemoving, leavingConnection
-- Second Part
print(queueTable, "before")
table.insert(queueTable, player)
print(queueTable, "after")
if queueTable[player] then print("Got Player") end
-- Unimportant things continuation.
For some reason, before prints nil and after prints nil.
Only after I try firing the event again will it show and add onto it (in a clunky manner as well).
Doing print(queueTable[player]) also leads to nil.
Since I’m getting no results, I’m pretty sure I’m using table.insert() wrong, any hint/reason/course to how table.insert() works? Thanks. Yes I checked devhub, couldn’t find anything about it or maybe I’m searching wrong.