Attempt to index nil with parent

Hello. Im getting this error Attempt To Index Nil With Parent and i don’t really know how to fix it i have tried many solutions but i hasn’t worked.

The script functions fine but im getting really annoyed by the fact its spamming the error in output so help is appreciated.

Here is my script: Its at line 17

--//Services
local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")
local RunService = game:GetService("RunService")

--//Variables
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()

--//Tables
local ActiveGuis = {}

--//Functions
RunService.RenderStepped:Connect(function()
	local mouseTarget = Mouse.Target

	if CollectionService:HasTag(mouseTarget, "ShowNPCButton") or CollectionService:HasTag(mouseTarget.Parent, "ShowNPCButton") then
		local Torso = mouseTarget.Parent.Torso
		Torso.ButtonBillboardGui.TextButton.Visible = true
		Torso.TextBillboardGui.TextLabel.Visible = true

		table.insert(ActiveGuis, Torso.ButtonBillboardGui.TextButton)
		table.insert(ActiveGuis, Torso.TextBillboardGui.TextLabel)
	elseif #ActiveGuis > 0 then
		for i, gui in ipairs(ActiveGuis) do
			gui.Visible = false
		end

		table.clear(ActiveGuis)
	end
end)

mouseTarget is nil, That’s why it says your attempting to index nil with Parent.

So just add:

--//Functions
RunService.RenderStepped:Connect(function()
	local mouseTarget = Mouse.Target
        if(not mouseTarget)then return end;
1 Like

thank you so much i really appreicate it