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

GUI and camera interaction problems?

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

✓ Accepted answer

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)

1 comment

0

I changed it to the way you said but the camera wont change still

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