Hello! I’m making a simulator game and each person is going to have their own little island. On the main area there is a teleport button that when clicked, a GUI pops with the option to teleport to your island or someone else’s. My only problem is I am struggling on making the script(s) that assign each player their own island upon joining the game. I have managed to make a script that assigns each player a number in a table that will be shown below on what it exactly does, but I’m at a road block and need some help.
-------Setups-------
place = {Vector3.new(0,0,0),Vector3.new(0,0,0),Vector3.new(0,0,0),Vector3.new(0,0,0),Vector3.new(0,0,0),Vector3.new(0,0,0),Vector3.new(0,0,0),Vector3.new(0,0,0),Vector3.new(0,0,0),Vector3.new(0,0,0),Vector3.new(0,0,0),Vector3.new(0,0,0)}
owners = {0,0,0,0,0,0,0,0,0,0,0,0}
busy = false --interaction failsafe
local players = game:GetService("Players")
-------Functions-------
local function update()
busy = false
print(busy)
print(owners)
end
local function onPlayerAdded(player)
busy = true
local temp = {}
local i
table.move(owners,1,12,1,temp)
i = table.find(temp,0)
table.remove(temp,i)
table.insert(temp,i,player.UserId)
table.clear(owners)
table.move(temp,1,12,1,owners)
update()
end
local function onPlayerRemoved(player)
busy = true
local temp = {}
local i
table.move(owners,1,12,1,temp)
i = table.find(temp,player.UserId)
table.remove(temp,i)
table.insert(temp,i,0)
table.clear(owners)
table.move(temp,1,12,1,owners)
update()
end
-------Events-------
players.PlayerAdded:Connect(onPlayerAdded)
players.PlayerRemoving:Connect(onPlayerRemoved)
-------Random-------
On the image above, when a player leaves it sets the number they were assigned to as 0.
If you know how I can connect this to the system I’m looking to make or if you have a better way of doing it, please let me know!