Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

assigning slots to player?

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

3 comments

0

Can you give a little more info about what you are trying to do?

0

First of all, "Workspace" is depreciated, try using "workspace".

0

^ what are you talking about?? I did game.Workspace not "wOrkSPacE"

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.