local Tool = script.Parent local mouse = game.Players.LocalPlayer:GetMouse() local ToolEnabled = true Tool.Activated:connect( function() if not ToolEnabled then return end ToolEnabled = false if mouse.Target.Position.magnitude == _G.ve1.magnitude and _G.humanoid1.Health < 101 then _G.humanoid1.Health = _G.humanoid1.Health + 6 end
ve1 is a vector3
This is not the full script but the error is in the "if statement"
The reason this errors is because mouse.Target
is specifically meant for targeting parts. The skybox isn't a part, and because of that, it has no position or magnitude, which causes an error. There is no target, so it is a nil value. Try adding a conditional that checks for if there's a target in the first place, and that might fix your issue.
Hope this helped.
You need to check whether your target exists!
if mouse.Target ~= nil then if mouse.Target.Position.magnitude == _G.ve1.magnitude and _G.humanoid1.Health < 101 then _G.humanoid1.Health = _G.humanoid1.Health + 6 end end
The following statement checks whether the mouse's target is an object. To avoid errors simply put your code in-between the statement below.
if mouse.Target ~= nil then end
Example:
local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() mouse.Move:connect(function() if mouse.Target ~= nil then print(mouse.Target.Name) end end)