Can someone help me with learning tables?

  1. What do you want to achieve?

I want to know how to use tablets, i used to learn ( not so much)

local TBL = {}

wait(1)
table.insert(TBL, game.Workspace.Part)
wait(5)
table.remove(TBL, game.Workspace.Part)
wait(0.01)
workspace.Part:Destroy()

  1. What is the issue?

I don’t have a issue

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Yes, i searched in Developer Hub but that don’t helped me

If u want to help me, chat with me on discord: pro_developer213#2019

Can someone help me?
(I can’t give Something but i can script Something for u If u want)

1 Like
  1. Tables*
  2. Programming in Lua : 2.5
3 Likes

I will try it, thanks for the help

It helped me but that don’t help me to know If a one table can be accesed by more scripts, can it be accesed by more scripts?

If you put the table in a module then, yes.

Also do not expect other users to teach you Lua unless they want to… If you want to learn lua then click here.

:+1:t2: Have fun!

1 Like

Put the table in _G. Like so: _G.Table = {}. Don’t use modulescripts.

1 Like

tables are really easy and simple , I understand if a lot of information like

Programming in Lua : 2.5 is difficult to understand, here is an example of tables.

admins =--this is the table, called admins
{
   "MillerrIAm";
   "NemesisY2J";
   "Sonicxman";
   "Dewwy5280";
}

--now you can refer to that

plr.LocalPlayer.Chatted:Connect(function(plr,msg)
	if table.find(admins, plr.Name) then--if the person who's messaging has his --name in the table then, do this..**I took this as an example from @zQ86 
		if msg == msg1 then
			Event:FireServer("Ring the bell!")
		end
	end
end)

--this is all an example, of how you can use tables in the simplest way I mean,
2 Likes

there is 3 solutions but i can give only one sorry

it’s alright you can always change it, but i’m not telling you to, you have to decide what , if marked, will help people who are searching for help on tables, this example or just another link. I mean a link on’t help without an example right? Anyways its up to you

1 Like

this will help me alot thx man

Any Programmer who knows what they are doing wouldn’t recommend using _G and Shared because they compromise performance, I’ve never seen anyone recommend using Global Tables before.

You should use Modules they are better than _G and Shared

6 Likes

hi but how can they can compromise performance? i used it and it works great

https://devforum.roblox.com/t/when-should-i-use--g-instead-of-a-modulescript/13444

https://devforum.roblox.com/t/what-are-module-scripts-what-do-they-serve/256698/4

Shared and _G existed before ModuleScripts, so it was used back in the day iirc.

Global Tables are much slower than using Modules hence compromising performance, less versatile and probably deprecated one way or another.

Pro tip (Try searching for answers before asking or creating a thread)

i will use it, if it works same or better i will use it

CC @RuizuKun_Dev, This is adding onto what you were saying in your post.

I wouldn’t recommend _G because ModuleScrips serve as a much, much, much better alternative. _G may seem good to use initially when you have a small code base but when you start using it extensively everywhere you will find yourself getting confused as to what is and isn’t stored in it. This makes reading and updating your code a lot harder. Be very careful when using _G and only use it when you really need to.

_G has so many limitations compared to using ModuleScrips: You can’t store stuff for both client and server to access. You won’t be able to take full advantage of OOP with _G because of how much more confusing it will be. Why would you store all your global stuff in one table?

Why modules are a better alternative:
ModuleScripts have so many more advantages than _G because of how organisation friendly and versatile they are. Modules allow you to split your code, in your case tables, into smaller chucks making reading, updating and maintaining your code a lot easier. Compared to _G modules are a lot more visually friendly as well.

If you want the client and the server to both access the same table, like a configuration module, then this can be done easily by placing a module within ReplicateStorage. Whereas with _G this is non existent because the client and server both have separate _G tables.

Another advantage with using modules is that you can OOP a lot easier than you would be able to with using _G. With the use of modules you can have a separate module for each object(I think this is the right terminology) you create making it visually easier to update. You can also make it so the client and server can both access the module as explained above.

i arleady stoped using _G becouse i don’t know how to use it and thats why it works good with module sctipts