Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Attempt to index nil with 'Touched'?

I made a touched event and It doesn't work. I can't find out why, can someone help?

local plotsFolder = game.Workspace.Plots
local plots = plotsFolder:GetChildren()

plots.PlotArea.Touched:Connect(function(player)
	
	local ownerValue = plots.OwnerValue
	
	if player.Name == ownerValue.Value then
		print(player.Name.." is the owner of the house")
	else
		return false
	end
end)

1 answer

Try this, Since it doesn't know what player is, just by touch it could've been anything and it defines as a player so try this

local plotsFolder = game.Workspace.Plots
local plots = plotsFolder:GetChildren()

plots.PlotArea.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		
		local ownerValue = plots.OwnerValue

		if player.Name == ownerValue.Value then
			print(player.Name.." is the owner of the house")
		else
			return false
		end
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.