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

Hello! I'm having troubles with output, it's saying I have a nil value when it is clearly stated

Asked by 11 years ago

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:

01local camera = game.Workspace.CurrentCamera
02local target = game.Workspace.Heli.Heli1
03local target2 = game.Workspace.Heli.Heli2
04camera.CameraType = "Scriptable"
05camera.CameraSubject = target2
06 camera.CoordinateFrame = CFrame.new(target2.Position)
07                          * CFrame.Angles(0, math.rad(90), 0)
08wait(0.1)
09game.Players.LocalPlayer.PlayerGui.TalkGui.script1.Disabled = false
10while wait() do
11if script.Heli3Ready.Value == true then
12camera.CameraSubject = target
13 camera.CoordinateFrame = CFrame.new(target.Position)
14                          * CFrame.Angles(0, math.rad(180), 0)
15local modelMode = true
View all 31 lines...
0
also, I'd like to know how to set a max on how far you can turn left or right! deputychicken 226 — 11y

2 answers

Log in to vote
0
Answered by 11 years ago

If you want to detect if the player's mouse is in a GUI, use this:

01local leftframe = script.Parent --Assume this script is inside of LeftFrame, the frame being inside of a screenGUI with RightFrame and LeftFrame
02 
03local rightframe = script.Parent.Parent.RightFrame
04leftframe.MouseEnter:connect(function()
05    --Put code that you want to execute when the mouse is in this frame here
06end)
07leftframe.MouseLeave:connect(function()
08    --Put code that you want to execute when the mouse leaves the frame here
09end)
10rightframe.MouseEnter:connect(function()
11    --Put code that you want to execute when the mouse is in this frame here
12end)
13rightframe.MouseLeave:connect(function()
14    --Put code that you want to execute when the mouse leaves the frame here
15end)

GUI objects (other than ScreenGUi and other base GUI holders) come with that event.

Ad
Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
11 years ago

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.

Answer this question