Plot System Error

Hello, I’m currently trying to code a plot system, but I’m having trouble with my script. I’m following a tutorial, and the part I’m having trouble with is displayed here.

This is my script so far (not the finished script, but the same as the tutorial at the point i’m at from what I can see, but does not replicate what his does.) When I click my left/right arrows, there’s nothing in the “SelectedPlot” value, no count up or down like Alvin has in his video if you look in his properties section. Does anyone know whats going wrong?

local Player = game.Players.LocalPlayer
local PlotSelect = script.Parent:WaitForChild("PlotSelect")

local Frame = PlotSelect:WaitForChild("Frame")
local Left = Frame:WaitForChild("Left")
local Right = Frame:WaitForChild("Right")

local SelectedPlot = Frame:WaitForChild("SelectedPlot")

local plots = game.Workspace.Plots

local function findUnoccupiedPlots()
	local availablePlots = {}
	for i, plot in pairs(Plots:GetChildren()) do
		if plot.Occupant.Value == nil then
			table.insert(availablePlots,plot)
		end
	end
	return availablePlots
end

local plots = findUnoccupiedPlots()

local index = 1

SelectedPlot.Value = plots[1]

Right.MouseButton1Click:Connect(function()
	if Plots:FindFirstChild("Plot"..index-1) then
		index -= 1
	else
		index = 9
	end
	
	SelectedPlot.Value = plotsTable[index]
end)

Left.MouseButton1Click:Connect(function()
	if Plots:FindFirstChild("Plot"..index+1) then
		index += 1
	else
		index = 1
	end
end)

Hi,

Do you have any errors in your console?

how do i check that? i’m sorry, i’m pretty new to scripting

In the view button at the top of studio there will be an option for output.

I think it may be something to do with this line:

local plots = game.Workspace.Plots

everywhere else in the script references this as ‘Plots’ which makes me believe that that line should be:

local Plots = game.Workspace.Plots

as Lua and most programming languages are case sensitive.

Hope this helps :slight_smile:

Edit: Also that is what it is in @Alvin_Blox’s code from the livestream

I tried that but it still didn’t work. I did what you showed me with the outputs and this is what it said:

 Players.xshaybie.PlayerGui.Client:29: attempt to call a nil value  -  Client - Client:29

maybe try this

local Player = game.Players.LocalPlayer
local PlotSelect = script.Parent:WaitForChild("PlotSelect")

local Frame = PlotSelect:WaitForChild("Frame")
local Left = Frame:WaitForChild("Left")
local Right = Frame:WaitForChild("Right")

local SelectedPlot = Frame:WaitForChild("SelectedPlot")

local Plots = game.Workspace.Plots

local function findUnoccupiedPlots()
	local availablePlots = {}
	for i, plot in pairs(Plots:GetChildren()) do
		if plot.Occupant.Value == nil then
			table.insert(availablePlots,plot)
		end
	end
	return availablePlots
end

local plotsTable = findUnoccupiedPlots()

local index = 1

SelectedPlot.Value = Plots[1]

Right.MouseButton1Click:Connect(function()
	if Plots:FindFirstChild("Plot"..index-1) then
		index -= 1
	else
		index = 9
	end
	
	SelectedPlot.Value = plotsTable[index]
end)

Left.MouseButton1Click:Connect(function()
	if Plots:FindFirstChild("Plot"..index+1) then
		index += 1
	else
		index = 1
	end
end)

It now says nothing in the output, and I still don’t see the value in the properties

Weird… Make sure you are looking at the properties of the player (not starter GUI) and the code only changes the property when you press the right button. (you haven’t included that line in the left function, yet) Also it seems unintuitive why does right decrease the value?

Okay, so, I looked inside of the player properties instead and the value did appear, and I changed the left/right around for the increase/decrease value, and the output now says this:

  17:41:05.887  Players.xshaybie.PlayerGui.Client:35: attempt to index nil with number  -  Client - Client:35

Is this your code for that section?

Left.MouseButton1Click:Connect(function()
	if Plots:FindFirstChild("Plot"..index-1) then
		index -= 1
	else
		index = 9
	end
	
	SelectedPlot.Value = plotsTable[index]
end)

Right.MouseButton1Click:Connect(function()
	if Plots:FindFirstChild("Plot"..index+1) then
		index += 1
	else
		index = 1
	end

	SelectedPlot.Value = plotsTable[index]
end)

I don’t immediately see why it isn’t working

this is my script

local Player = game.Players.LocalPlayer
local PlotSelect = script.Parent:WaitForChild("PlotSelect")

local Frame = PlotSelect:WaitForChild("Frame")
local Left = Frame:WaitForChild("Left")
local Right = Frame:WaitForChild("Right")

local SelectedPlot = Frame:WaitForChild("SelectedPlot")

local Plots = game.Workspace.Plots

local function findUnoccupiedPlots()
	local availablePlots = {}
	for i, plot in pairs(Plots:GetChildren()) do
		if plot.Occupant.Value == nil then
			table.insert(availablePlots,plot)
		end
	end
	return availablePlots
end

local plotsTable = findUnoccupiedPlots()

local index = 1

SelectedPlot.Value = Plots[1]

Right.MouseButton1Click:Connect(function()
	if Plots:FindFirstChild("Plot"..index-1) then
		index -= 1
	else
		index = 9
	end
	
	SelectedPlot.Value = plotsTable[index]
end)

Left.MouseButton1Click:Connect(function()
	if Plots:FindFirstChild("Plot"..index+1) then
		index += 1
	else
		index = 1
	end
end)

and the explorer

image

can you try printing the availablePlots variable? By putting this line: print(plotsTable) above the line that is erroring and see what the output says?

Where do I find the error line? When I look at the top bar it says there’s no error in my script… so I’m not sure whats wrong with it

Oh I don’t know either maybe try attaching your studio file so I can try and fix it?

Essie’s Designer Mall.rbxl (186.3 KB)

there it is ^

thank you so much for taking the time out of your day to help, it’s very appreciated!

Hi, I am busy at the moment do you mind if I look at it when I get back to my computer in maybe an hour?

Above

Right.MouseButton1Click:Connect(function()

replace:

SelectedPlot.Value = Plots[1]

with:

SelectedPlot.Value = plotsTable[1]

I just changed that and its displays values.

this worked, only slightly though. when i scroll through the numbers it counts randomly through the plots instead of in order, and the left button doesn’t work

The left button doesn’t work because you have not included this at the bottom of its function:

SelectedPlot.Value = plotsTable[index]