Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I need help with a script! Can anyone help?

So my script makes it so that the player looks right when player's mouse enters a gui. the only problem is, I set it so that the function only works when a value is true. It still functions. Here is the script!:

if script.Heli6Ready.Value == true then
  player.PlayerGui.Ermg.Left.MouseEnter:connect(function()
	if script.LookingLeft.Value == false then
	script.LookingLeft.Value = true
	camera.CameraSubject = target
camera.CoordinateFrame = CFrame.new(target.Position)
                         * CFrame.Angles(0, math.rad(181), 0)
wait(0.01)
camera.CameraSubject = target
camera.CoordinateFrame = CFrame.new(target.Position)
                         * CFrame.Angles(0, math.rad(182), 0)
wait(0.01)
camera.CameraSubject = target
camera.CoordinateFrame = CFrame.new(target.Position)
                         * CFrame.Angles(0, math.rad(183), 0)
end
end)
script.Heli6Ready.Value = false
script.Heli4Ready.Value = true
end

1 answer

✓ Accepted answer

Your condition on line 01 affects the statement:

player.PlayerGui.Ermg.Left.MouseEnter:connect( somefunvalue )

Notice that this is the connection, and not actually the event firing. This only happens once.

It is the execution of somefunvalue which happens repeatedly, and which needs to check:

player.PlayerGui.Ermg.Left.MouseEnter:connect(function()
	if script.Heli6Ready.Value == true then
		if script.LookingLeft.Value == false then
			script.LookingLeft.Value = true
			camera.CameraSubject = target
			camera.CoordinateFrame = CFrame.new(target.Position)
				* CFrame.Angles(0, math.rad(181), 0)
			wait(0.01)
			camera.CameraSubject = target
			camera.CoordinateFrame = CFrame.new(target.Position)
				* CFrame.Angles(0, math.rad(182), 0)
			wait(0.01)
			camera.CameraSubject = target
			camera.CoordinateFrame = CFrame.new(target.Position)
				* CFrame.Angles(0, math.rad(183), 0)
		end
	end
end)

I cannot guess from what you have provided where these two lines belong:

script.Heli6Ready.Value = false
script.Heli4Ready.Value = true


Style suggestion:

You don't need to check if a value is == true.

if script.Heli6Ready.Value then

Is shorter and usually clearer.

Similarly, instead of using == false, use

if not script.LookingLeft.Value then

This discussion is preserved as it was. New answers, comments, and votes are closed.