I am trying to make some sort of anti exploits for events that only fires once when player is not in main menu so I am trying to add player names into the table, but I don’t want their index to be as a number I want it to be as a string so it’s like this
Thanks for the reply, I have tried this method but it resets everytime new player fires the event I want every player in the game to have their name in the table and remove their name whenever I want
This is maybe because when you try to add a player you use the same index as the others thus when using Players["Class"] = Player you’re actually changing the other index and not creating a new one
It seems like you have multiple indexes with the same name.
Tables indexes must be unique and cannot be the same or it’ll overwrite something that already exists or prevent you from properly indexing it.
Try something like this:
local Players = {}
game:GetService("Players").PlayerAdded:Connect(function(player)
Players[player.Name] = player
end)
Because Players[player.Name] doesn’t exist yet, it is created and has it’s value set to the player object.
This what you were looking for?
Here’s a more ordered and structured way of keeping player data in a table.
The way it is currently done seems a bit chaotic and inconvenient to say the least.
This may help you and save you a lot of headaches later on.
You need an overarching table to store the players’ details.
local playerAccessories = {}
game:GetService("Players").PlayerAdded:Connect(function(player)
playerAccessories[player] = {} -- these are the player's accessories
end)
...:Connect(function()
playerAccessories[player]["Hats"] = "wowow" -- We can now set individual details of the player's accessories.
end)
game:GetService("Players").PlayerRemoving:Connect(function(player)
playerAccessories[player] = nil -- remove it to prevent a memory leak
end)
like the other reply that was above the method you are telling me is to only modify [“Hats”] but I don’t want to modify it I want to add multiple data for a player without modifying any of them
this is my current script:
local Players = {} -- Player names
game:GetService("Players").PlayerAdded:Connect(function(player)
Players[player] = {}
end)
game:GetService("Players").PlayerRemoving:Connect(function(player)
if Players[player] then
Players[player] = nil
end
end)
function PlayerNames.RemovePlayerName(EventName, player)
for i,v in pairs(Players) do
if player == i then
Players[player] = nil
print(Players)
print("Removed player from the List")
end
end
end
function PlayerNames.AddPlayerName(EventName, player)
Players[player] = EventName
print(Players)
end
function PlayerNames.CheckInTheTable(EventName, player)
for i,v in pairs(Players) do
if player == i and EventName == v then
return true
end
end
end
I forgot to mention that player equals to player.Name since this script is part of a ModuleScript and when server scripts require the module and call function it directly sends player.Name. so this is not gonna change anything at all