Help On My Game!

I want to make an island tycoon. Everyone would get a separate island. How would I make it so everyone spawns on a different island. Keep in mind, I am a beginner at coding.

Make each island as if it’s a plot.

Have a dictionary inside each script for taken plots, for example:

local takenPlots = {
    ["plotId"]="playerName"
}

Then when a player joins, have it loop through each plot and check if its taken, if its not taken then assign it to player.

I just coded a similar thing, so here’s an example:

module.ownedPlots = {} -- stored in format ["plotId"]="plrName"

function module.assignPlot(plr)
	for i = 1,#game.Workspace.Plots:GetChildren(),1 do
		if not module.ownedPlots[tostring(i)] then
			module.ownedPlots[tostring(i)] = plr.Name
			print(module.ownedPlots)
			return i
		end
	end
end

function module.unassignPlot(plr)
	for i = 1,#game.Workspace.Plots:GetChildren(),1 do
		if module.ownedPlots[tostring(i)] then
			if module.ownedPlots[tostring(i)] == plr.Name then
				module.ownedPlots[tostring(i)] = nil
				print(module.ownedPlots)
				return
			end
		end
	end
end

In that example, you call the first function and it returns a plot that’s been assigned to the player. Then you call the second function when the player leaves to free up the plot again.

1 Like