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

Why is 'Target' a nil value?

game:GetService("RunService").RenderStepped:Connect(function()
	local Target = Mouse.Target or nil
	if Target.Name == "Hitbox" then
		local SelectedItem = Target.Parent
		local TargetUI = script.Parent.Hovering
		if SelectedItem.Information:FindFirstChild("Enabled") and SelectedItem.Parent.Parent.TycoonOwner.Value == Player.Name then
			TargetUI.Visible = false
			TargetUI = script.Parent.HoveringMine
		else
			script.Parent.HoveringMine.Visible = false
		end
		TargetUI.Position = UDim2.new(0, Mouse.X + 20, 0, Mouse.Y + 8)
		TargetUI.ItemName.Text = SelectedItem.Name
		TargetUI.ItemLevel.Text = "Level " .. game.Players[SelectedItem.Parent.Parent.TycoonOwner.Value].SaveStats[SelectedItem.Name].Value
		if TargetUI.Name == "HoveringMine" then
			UpdateToggle(SelectedItem)
		end
		TargetUI.Visible = true
	else
		Mouse.TargetFilter = Target
		script.Parent.HoveringMine.Visible = false
		script.Parent.Hovering.Visible = false
	end
end)

Players.Hexorium.PlayerGui.Interface.ClientHandler:285: attempt to index local 'Target' (a nil value)

^ error

The line in question is line 3 on the code block above. Any reason why this error occurs?

2 comments

0

use if Target and Target.Name == "Hitbox" then

0

You should be checking if the target exists. And what is with that "ternary" statement on line 2?

1 answer

smh, why do u even bother ????

local Target = Mouse.Target or nil....

whats Mouse, show that please...

"OR NIL" now if you have "nil" normally no one checks for its name??

Target.Name

of course its gonna error if "Target" is nil...

1 comment

1

ikr

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