this shouldent give me an error
1 | script.Parent.Position = UDim 2. new( 0 ,Mouse.X - 100 , 0 ,Mouse.Y + 60 ) |
2 | if Mouse.Target = = nil or (Mouse.Target.Position - Player.Character.Torso.Position).magnitude > 7 then script.Parent.Visible = false |
3 | elseif Mouse.Target ~ = nil and (Mouse.Target.Position - Player.Character.Torso.Position).magnitude < 7 then |
ERROR
1 | 14 : 03 : 55.938 - Players.ObStactionD 3 stroy 3 r.PlayerGui.MouseTrack.Frame 2. LocalScript: 9 : attempt to index field 'Target' (a nil value) |
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.
01 | local popup = script.Parent; |
02 | local target = Mouse.Target; |
03 | local char = player.Character; |
04 |
05 | popup.Position = UDim 2. new( 0 , (Mouse.X - 100 ), 0 , (Mouse.Y + 60 )); |
06 |
07 | if (target and char) then |
08 | -- To check for the distance we have to have the target's position, so it can't be nil. |
09 | local dist = player:GetDistanceFromCharacter(target.Position); |
10 | 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 |
11 | else |
12 | popup.Visible = false ; |
13 | end |