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:

_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:

_G.Players = {}

game:GetService("Players").PlayerAdded:Connect(function(player)
    if not _G.Players[player.UserId] then
        _G.Players[player.UserId] = true 
    end
end)

-- And if you want to delete it when they leave: 

game:GetService("Players").PlayerRemoving:Connect(function(player)
    if _G.Players[player.UserId] then
        _G.Players[player.UserId] = nil
    end
end)

Hope this helps

Ad

Answer this question