How do you use :FindFirstChild() in a module script?

Hey, so I’ve been making a plot selection system and I’ve been wondering how I can use : FindFirstChild() inside of a module script.

Example of using :FindFirstChild() inside of a normal brick.

local Variable = 1

game.workspace: FindFirstChild("Part".. Variable).Anchored = false

But I don’t want to use this inside of something physical, I want to use this inside to find something inside of a module script:

Module Script

local Plots = {
	
	AvailablePlots = true,
	
	Plot1 = {
		Claimed = false,
		Owner = nil,
		Location = game.Workspace.Plots:WaitForChild("Plot1")
	},
	Plot2 = {
		Claimed = false,
		Owner = nil,
		Location = game.Workspace.Plots:WaitForChild("Plot1")
	},
	Plot3 = {
		Claimed = false,
		Owner = nil,
		Location = game.Workspace.Plots:WaitForChild("Plot1")
	},
	Plot4 = {
		Claimed = false,
		Owner = nil,
		Location = game.Workspace.Plots:WaitForChild("Plot1")
	}
}

return Plots

Script

local SelectPlotRemoteEvent = game.ReplicatedStorage:WaitForChild("Remotes").PlotSelection.SelectPlot
local UpdateCanvasRemoteEvent = game.ReplicatedStorage:WaitForChild("Remotes").PlotSelection.ServerToClient.UpdateCanvas

local PlotOwners = require(game.ReplicatedStorage:WaitForChild("Modules").PlotDataModules.PlotData)

function SelectPlot(player, Selected, Max)
	local SelectedPlot = game.Workspace.Plots:WaitForChild("Plot".. Selected)
	if PlotOwners.Plots:FindFirstChild("Plot".. Selected).Claimed == true then
		print(player.. " was reported plot wipe exploit.")
		player:Kick("ERROR: Please rejoin, there was a problem.")
	else
		PlotOwners.Plots:FindFirstChild("Plot".. Selected).Claimed = true
		PlotOwners.Plots:FindFirstChild("Plot".. Selected).Owner = player
	end
	
	--UpdateCanvasRemoteEvent:FireClient(player, SelectedPlot)
end

SelectPlotRemoteEvent.OnServerEvent:Connect(SelectPlot)

Now unfortunately, this doesn’t work correctly. Any ideas?

1 Like

Plots is a dictionary, therefore you don’t use FindFirstChild.
To get a value inside a dictionary, you either do:

Dictionary.Value
or
Dictionary[Value]

The latter allows you to use variables, Dictionary[“Plot”… Selected].Owner = player

4 Likes

Oh, I wasn’t aware I was able to just simply do that! THANKS.

1 Like

This didn’t work. Any ideas why?

local SelectPlotRemoteEvent = game.ReplicatedStorage:WaitForChild("Remotes").PlotSelection.SelectPlot
local UpdateCanvasRemoteEvent = game.ReplicatedStorage:WaitForChild("Remotes").PlotSelection.ServerToClient.UpdateCanvas

local PlotOwners = require(game.ReplicatedStorage:WaitForChild("Modules").PlotDataModules.PlotData)

function SelectPlot(player, Selected, Max)
	local SelectedPlot = game.Workspace.Plots:WaitForChild("Plot".. Selected)
	if PlotOwners.Plots["Plot".. Selected].Claimed == true then
		print(player.. " was reported plot wipe exploit.")
		player:Kick("ERROR: Please rejoin, there was a problem.")
	else
		PlotOwners.Plots["Plot".. Selected].Claimed = true
		PlotOwners.Plots["Plot".. Selected].Owner = player
	end
	
	--UpdateCanvasRemoteEvent:FireClient(player, SelectedPlot)
end

SelectPlotRemoteEvent.OnServerEvent:Connect(SelectPlot)

What is game.Workspace.Plots? Take a photo of the explorer

I didn’t use that variable at all, I was gonna use it but then decided not to. I forgot to delete it, so it doesn’t do anything.

In the ModuleScript, on Location you have game.Workspace.Plots. What is that? A folder, a model, what is it?

Screen Shot 2020-12-10 at 8.33.01 AM

Its support to be used for a remote event, the remote event will send the plot location to a different script later. This is where the remote event is though:
Screen Shot 2020-12-10 at 8.33.43 AM

Print Plotowners.Plots and see what you get, check the table and send it in. If you print a table there’s a arrow next to it, click it and it’ll open. Send the content

I’m guessing I didn’t use require or the location of the module script correctly, lemme check.

That didn’t work, its still all correct.

its because your Plots table isn’t inside the module. its in its own local variable.

Change it to:

module.Plots = {}

1 Like

oh I see.

yea that still will error because “Plots” doesn’t exist in the module.

You would need to go right into Plot1 by doing: PlotOwners[“Plot”…Selected]

The setup I was referring to:

local module = {}
module.Plots = {}
return module
1 Like

Oh it worked! Thanks so much, your a life saver. :slight_smile:

1 Like