ScreenGui not being found in local script after not using script.Parent?

Working script: (inside ScreenGui)

local localPlayer = game.Players.LocalPlayer
local currentCamera = workspace.CurrentCamera
local exit = script.Parent.exit -- deleted this in Non-working script
local looking = false
local tweenTime = 1
local debounceTime = 0.5
local active = false
local camera1 = game.Workspace.camera1
local endCFrame = camera1.CFrame

exit.MouseButton1Click:Connect(function()
	if active then return end active = true
	looking = not looking
	if looking then
		repeat 
			wait (0.1) currentCamera.CameraType = Enum.CameraType.Scriptable
		until currentCamera.CameraType == Enum.CameraType.Scriptable
		
		game.TweenService:Create(currentCamera, TweenInfo.new(tweenTime, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {CFrame = endCFrame}):Play()
		wait(tweenTime+debounceTime)
		
	else
		currentCamera.CameraType = Enum.CameraType.Custom
		wait(debounceTime)
	end
	active = false
end)

Non-working script: (outside of ScreenGui)

local screenGui = game.StarterGui.ScreenGui --added this
local localPlayer = game.Players.LocalPlayer
local currentCamera = workspace.CurrentCamera
local exit = screenGui.exit -- something went wrong here
local looking = false
local tweenTime = 1
local debounceTime = 0.5
local active = false
local camera1 = game.Workspace.camera1
local endCFrame = camera1.CFrame

exit.MouseButton1Click:Connect(function()
	if active then return end active = true
	looking = not looking
	if looking then
		repeat 
			wait (0.1) currentCamera.CameraType = Enum.CameraType.Scriptable
		until currentCamera.CameraType == Enum.CameraType.Scriptable
		
		game.TweenService:Create(currentCamera, TweenInfo.new(tweenTime, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {CFrame = endCFrame}):Play()
		wait(tweenTime+debounceTime)
		
	else
		currentCamera.CameraType = Enum.CameraType.Custom
		wait(debounceTime)
	end
	active = false
end)

The only thing that changed is that I made a local variable for screengui to find the exit gui instead of using script.Parent so I can move the local script if I need to. I dont really know what is wrong.

3 Likes

Instead of using

local exit = screenGui.exit

try to specify where the screenGui is sort of like this:

local exit = game.StarterGui.screenGui.exit

I’m not quite sure if this works I know it’s the same thing but give it a try. Sometimes it’s weird like that.

1 Like