Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i name/create variables in-game?

Asked by 6 years ago
Edited 6 years ago

I've recently been trying to make a script that stores a _G table variable for every player on the server. To do that i need to make sure that every _G instance has a different name so they don't interfere with eachother. So i came up with the excellent idea to use player ID's, But here's the problem. Is there any way to create a variable IN-GAME with a custom name?

Like maybe:

1_G.["Table" .. 129265755] = {1,2,3}

But it doesn't work, Is there any other way i could do this?

I'm fairly new to "Advanced" coding so help would be greatly appreciated.

0
Remove the dot after _G Amiaa16 3227 — 6y

1 answer

Log in to vote
0
Answered by
metryy 306 Moderation Voter
6 years ago
Edited 6 years ago

You can make a new index with the player's UserId like this:

01_G.Players = {}
02 
03game:GetService("Players").PlayerAdded:Connect(function(player)
04    if not _G.Players[player.UserId] then
05        _G.Players[player.UserId] = true
06    end
07end)
08 
09-- And if you want to delete it when they leave:
10 
11game:GetService("Players").PlayerRemoving:Connect(function(player)
12    if _G.Players[player.UserId] then
13        _G.Players[player.UserId] = nil
14    end
15end)

Hope this helps

Ad

Answer this question