Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is 'Target' a nil value?

Asked by 6 years ago
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?

0
use if Target and Target.Name == "Hitbox" then yHasteeD 1819 — 6y
0
You should be checking if the target exists. And what is with that "ternary" statement on line 2? User#24403 69 — 6y

1 answer

Log in to vote
-1
Answered by 6 years ago

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
ikr User#5423 17 — 6y
Ad

Answer this question