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

I need help with a script! Can anyone help?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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
Ad

Answer this question