Hey guys, so I am trying to get it so that if the mouse targets a frame, the camera view changes to fit the left or right place, so it gives you a "Look around" can anyone see why it gives me this?: 22:01:12.063 - Workspace.Player1.Helicopterseeing:21: attempt to index local 'mousetarget' (a nil value) here is the script:
local camera = game.Workspace.CurrentCamera local target = game.Workspace.Heli.Heli1 local target2 = game.Workspace.Heli.Heli2 camera.CameraType = "Scriptable" camera.CameraSubject = target2 camera.CoordinateFrame = CFrame.new(target2.Position) * CFrame.Angles(0, math.rad(90), 0) wait(0.1) game.Players.LocalPlayer.PlayerGui.TalkGui.script1.Disabled = false while wait() do if script.Heli3Ready.Value == true then camera.CameraSubject = target camera.CoordinateFrame = CFrame.new(target.Position) * CFrame.Angles(0, math.rad(180), 0) local modelMode = true local player = game.Players.LocalPlayer local mouse = player:GetMouse() --Getting the player's mouse mouse.Move:connect(function() --When the mouse moves local mousetarget = mouse.Target if not modelMode then return elseif mousetarget:IsA("Frame") and mousetarget.Name == "Left" then camera.CoordinateFrame = CFrame.new(target.Position) * CFrame.Angles(0, math.rad(-10), 0) elseif mousetarget:IsA("Frame") and mousetarget.Name == "Right" then camera.CoordinateFrame = CFrame.new(target.Position) * CFrame.Angles(0, math.rad(-10), 0) end end) end end
If you want to detect if the player's mouse is in a GUI, use this:
local leftframe = script.Parent --Assume this script is inside of LeftFrame, the frame being inside of a screenGUI with RightFrame and LeftFrame local rightframe = script.Parent.Parent.RightFrame leftframe.MouseEnter:connect(function() --Put code that you want to execute when the mouse is in this frame here end) leftframe.MouseLeave:connect(function() --Put code that you want to execute when the mouse leaves the frame here end) rightframe.MouseEnter:connect(function() --Put code that you want to execute when the mouse is in this frame here end) rightframe.MouseLeave:connect(function() --Put code that you want to execute when the mouse leaves the frame here end)
GUI objects (other than ScreenGUi and other base GUI holders) come with that event.
If you point toward the sky, mouse.Target will be nil, add a check to make sure it's not before doing anything with it. The mouse works with CFrame positions, you can't detect GUI instances with mouse.Target.