I am having problems with a script, which gives away special values to players upon joining (all values are located in a table). Each time the 3rd player joins, the value is repeated (cause its already owned by 2nd player), and this script tries to notice if a chosen value is already owned by someone. Though, I am aware that it checks only one player's value, I don't know how to check ALL player values. Any answers?
local PlayerIndexTable = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
local function PlayerAdded(player)
local PlayerNum = game.Players:GetChildren()
if #PlayerNum == 1 then
local Index = Instance.new("IntValue")
Index.Parent = player
Index.Value = 1
end
if #PlayerNum > 1 then
for i,v in pairs(PlayerNum) do
if v:FindFirstChild("Value") ~= nil then
local ChosenValue = next(PlayerIndexTable, i)
if PlayerNum[i].Value.Vale ~= ChosenValue then
local Index = Instance.new("IntValue")
Index.Parent = player
Index.Value = ChosenValue
end
end
end
end
end
game.Players.PlayerAdded:Connect(PlayerAdded)

1 comment
Maybe another way to go about this would be to add a value to the player when they join, and then remove that value from the table of possible values. That way, everyone is getting a unique value without any checks.