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

GUI and camera interaction problems?

Asked by 10 years ago

I wrote this script so when I the user presses a button the camera will go back to custom and the GUI goes away, but when I put them together the camera does not go to scriptable.

player = script.Parent.Parent
c = game.Workspace.Camera

local open = true
local buttonPressed =  false

local button = script.Parent.Parent.StarterGui.ScreenGui.Frame.closeScreen

function changeButtonPressed ()

    buttonPressed = true

end

while open == true do
button.MouseButton1Click:connect(changeButtonPressed)

if buttonPressed == false then
    c.CameraType = "Scriptable"
    pos = Vector3.new(-832.984, 12.576, -680.927)
    targ = Vector3.new(-562.654, 1.741, -789.89)
    c.CoordinateFrame = CFrame.new(pos,targ)
    wait(1)
end
 if buttonPressed == true then
    c.CameraType = "Custom"
    open = false
    end
end

1 answer

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

When you switch to "Custom" you also set open to false.

This stops the loop (line 15), meaning it will not continue checking buttonPressed from then on.

Most appropriately it seems to just drop the while open == true do and just use while wait() do (since you do not have a wait otherwise).


Please note that it's wrong to connect your event in a loop. Line 16 should be moved to line 14. (Otherwise numerous times this will be re-connected, meaning late on, changeButtonPressed might be executed dozens of times whenever you click)

0
I changed it to the way you said but the camera wont change still CaptainRuno 40 — 10y
Ad

Answer this question