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

assigning slots to player?

Asked by
0msh 333 Moderation Voter
4 years ago

so I want to make a script where it changes the "PlayerSlot"'s name to the a player's name, assigning them the specific slot. But after I changed it the name is no longer "PlayerSlot" and cannot be changed again, thus breaks the script.

local names = game.Workspace:GetDescendants()
local playing = {}
while wait(3) do
for i, v in pairs(game.Players:GetPlayers()) do
    if v.Character and v.Character then
         table.insert(playing, v.Name)
    end
end
local slot = game.Workspace:FindFirstChild("Slot")
        slot.Slot1.PlayerSlot.Name = playing[1]
        if playing[2] then
        slot.Slot2.PlayerSlot.Name = playing[2]
        end
        if playing[3] then
        slot.Slot3.PlayerSlot.Name = playing[3]
        end

        end
0
Can you give a little more info about what you are trying to do? Regen_erate 25 — 4y
0
First of all, "Workspace" is depreciated, try using "workspace". matiss112233 258 — 4y
0
^ what are you talking about?? I did game.Workspace not "wOrkSPacE" 0msh 333 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

I created a script from scratch that'll assign slots to players.

local playing = {}
game.Players.PlayerAdded:connect(function(plr)
    playing[plr.Name] = true
end)
game.Players.PlayerRemoving:connect(function(plr)
    playing[plr.Name] = nil
end)

What I used for this was a Dictionary, it is basically a fancier and more complex array. The most important part of Dictionaries are keys. A key is a pointer used to access a variable inside the Dictionary.

You can think of a Dictionary as a shelf with different drawers. In this case the drawer you opened would be the Key. What you find inside this drawer is the value accessed by that specific Key.

Here's an example so you can understand:

local dictionary = {
    ["color"] = "blue",
    ["size"] = 5
}
print(dictionary.color)

Output:

blue

Conclusion: I used the dictionaries to assign a slot to players that joined. And when they left I set the value to nil, which deletes the value stored and the key itself.

Ad

Answer this question