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

I have a problem with an error and i dont know what it means anyhelp?

Asked by
DevingDev 346 Moderation Voter
7 years ago

this shouldent give me an error

    script.Parent.Position = UDim2.new(0,Mouse.X - 100,0,Mouse.Y + 60)
    if Mouse.Target == nil or (Mouse.Target.Position - Player.Character.Torso.Position).magnitude > 7 then script.Parent.Visible = false
    elseif Mouse.Target ~= nil and (Mouse.Target.Position - Player.Character.Torso.Position).magnitude < 7 then

ERROR

14:03:55.938 - Players.ObStactionD3stroy3r.PlayerGui.MouseTrack.Frame2.LocalScript:9: attempt to index field 'Target' (a nil value)

2 answers

Log in to vote
0
Answered by 7 years ago

Hey, @TheRevealerYT , I would like you to check this page of the Roblox Wiki :

http://wiki.roblox.com/index.php?title=Lua_errors

This wikipedia article is very usefull when you don't really know what error is that or how to fix a specific erorr. Hope this helped and, try to search more in google! If you searched a bit more , you would found this page and found your error and the direct fix to it.

Ad
Log in to vote
0
Answered by
jtefurd 50
7 years ago
local popup = script.Parent;
local target = Mouse.Target;
local char = player.Character;

popup.Position = UDim2.new(0, (Mouse.X - 100), 0, (Mouse.Y + 60));

if (target and char) then
    -- To check for the distance we have to have the target's position, so it can't be nil.
    local dist = player:GetDistanceFromCharacter(target.Position);
    popup.Visible = (dist > 7) and false or true; -- ProTip: this is a Terenary Operator, it's the same as saying if dist > 7 then popup.Visible = false else popup.Visible = true end
else
    popup.Visible = false;
end

Answer this question