How do I fix this camera

I have this camera for a welcome gui screen. Problem: It resets to it’s original position on respawn. I placed the script in StarterCharacterScripts because it’s the only place it works:

local twns = game:GetService("TweenService")

local player = game.Players.LocalPlayer

local cam = workspace.CurrentCamera

cam.CameraType = Enum.CameraType.Scriptable

cam.CFrame = workspace:WaitForChild("CamPart").CFrame

local startPos1 = CFrame.new(612.25, 34.5, -607.25)

local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
local target = {CFrame = player.Character:WaitForChild("UpperTorso").CFrame}

local anim1 = twns:Create(cam, tweenInfo, target)

player.PlayerGui.Welcome.TextButton.MouseButton1Click:Connect(function()
	player.PlayerGui.Welcome.TextButton:TweenPosition(UDim2.new(0.5, 0, 2, 0))
	player.PlayerGui.Welcome.TextLabel:TweenPosition(UDim2.new(0.5, 0, -2, 0))
	player.PlayerGui.Shop.TextButton:TweenPosition(UDim2.new(0.1, 0, 0.7, 0))
	wait(1)
	anim1:Play()
	print("Camera moved!")
	
	anim1.Completed:Wait()
	cam.CameraType = Enum.CameraType.Follow
	
	for i, v in pairs(player.PlayerGui:GetChildren()) do
		if v:IsA("ScreenGui") then
			v.Enabled = true
		end
	end
end)

Please don’t hesitate to give suggestions for this issue. Thanks!

What do you want it to do on respawn?

Will unchecking ResetOnSpawn for the GUI help?

1 Like

I already did that. It’s the camera I’m worried about:


It doesn’t fix on the player.

1 Like

Maybe between these two lines add:

cam.Cframe = target
1 Like

“cam.CFrame = workspace:WaitForChild(“CamPart”).CFrame”

When the player resets or dies the script plays again from the start.

3 Likes

Since this is in StarterCharacterScripts every time the players character is loaded, the script runs.

Instead try placing it into StarterPlayerScripts and running like this if you need the character or camera:

player.CharacterAdded:Connect(function(char)

    -- Run code

)
2 Likes

Have you tried moving this script to StarterPlayerScripts so that it doesnt kick in on respawn?

That didn’t work; I got an ‘attempt to index nil’ error.

That didn’t work either; It’s no longer zoomed out to the lobby when I join. (Even though it’s error-free)

1 Like

I would imagine you need a player added event instead of character added, that way it plays when you join game but not when you respawn. Try that same suggestion but change it to:

player.PlayerAdded:Connect(function(player)

Sadly, it didn’t work either. Plus the gui button wasn’t working anymore when I tried it.

If you want to do it the simple way just add in an “if” statement just outside of the “cam.CFrame = workspace:WaitForChild(“CamPart”).CFrame”. This will help ensure that it won’t play when the script resets.

1 Like

I understand what you’re saying but how do I write the script?

The script:

if cam.CFrame == game.Workspace:WaitForChild("CamPart") then
       player.PlayerGui:FindFirstChild("Welcome").Enabled = true
       player.PlayerGui:FindFirstChild("Welcome").TextButton.Visible = true
end)
1 Like