Attempt to index nil with 'Owner' (owner is a string value)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I am making a plot system where you can claim a house/plot when you touch a certain part

  2. What is the issue? I have a module with all the function required to run the plot. I made a function which will claim the plot for you. But within that function, there is a another function called checkClaim, this function checks to make sure the owner value which is inside the plot is empty. This is where the problem comes in: I get an error that reads:

attempt to index nil with ‘Owner’

  1. What solutions have you tried so far? Not many because I am not really sure

Module script:

local module = {}

function module.checkClaimed(plot)
	if plot.Owner.Value == "" or " " then -- the error occurs on this line
		return false -- plot is not claimed
	else
		return true -- plot is claimed
	end
end

function module.claimPlot(player, plot)
	
	local claimCheck = module.checkClaimed(plot) -- this is where the the function above is called
	
	-- claim plot
	if claimCheck == false then -- plot isnt claimed
		plot.Owner.Value = player.Name
		print(player.Name.." has claimed plot "..plot.Name)
		
-- the exterior and interior are seperate plots, this will claim the interior plot
		local interiorPlot = game.Workspace.Plots.Interiors:FindFirstChild(plot.Name) -- this will find the interior plot
		local interiorClaimCheck = module.checkClaimed(interiorPlot) -- the function is called again
		
		if interiorClaimCheck == false then
			interiorPlot.Owner.Value = player.Name
			print(player.Name.. " has claimed interior plot "..interiorPlot.Name)
		end
	end
end

return module

Script where the claimPlot() function is called

local module = require(script.Parent)

-- claim a plot
for _, house in pairs(game.Workspace.Plots.Houses:GetChildren()) do
	house.Teleport.Touched:Connect(function(hit) -- the plot will be claimed when touch the teleport part
		local character = hit.Parent
		if character:FindFirstChild("Humanoid") then
			local plr = game.Players:GetPlayerFromCharacter(character)
			module.claimPlot(character, house) -- call the function
		end
	end)
end

I’m sorry this is confsing I did my best to explain

local interiorPlot = game.Workspace.Plots.Interiors:FindFirstChild(plot.Name) -- this will find the interior plot

This is likely returning ‘nil’, print ‘interiorPlot’ to see.

1 Like

Ah I see. It did indeed return ‘nil’ because I only made 1 interior plot so far and I have 10+ houses

I simply just added

if interiorPlot then

end

Thanks!