How to make camera move smoothly on respawn

if u dont understand the title what i mean is, when the player dies, and then respawns, i dont want it to make it immeditaly make the camera where the player spawns, i want the camera to smoothly and quickly tween to where it the character is and then stop tweening

2 Likes

kinda like a gta character when spawning in?

1 Like

um i dont play gta so idk if ur thinking what im thinking

1 Like

Set the camera’s type to “Scriptable” and tween it. If the tween is completed you can set it back to “Custom”

1 Like

local LPlr = game.Players.LocalPlayer
local MyCam = workspace.CurrentCamera
local TS = game:GetService("TweenService")

local TweenDuration = 3

local JustDied = false

local function SetupChar()
	LPlr.Character.Humanoid.Died:Once(function()
		MyCam.CameraType = Enum.CameraType.Scriptable
		JustDied = true
	end)
	
	if JustDied == true then
		JustDied = false
		local Tween1 = TS:Create(MyCam, TweenInfo.new(TweenDuration, Enum.EasingStyle.Linear), {CFrame = LPlr.Character.Head.CFrame})
		Tween1.Completed:Once(function(state)
			if state == Enum.PlaybackState.Completed then
				MyCam.CameraType = Enum.CameraType.Custom
				MyCam.CameraSubject = LPlr.Character.Humanoid
			end
		end)
		Tween1:Play()
	end
end

repeat task.wait() until LPlr.Character
SetupChar()
LPlr.CharacterAdded:Connect(function()
	SetupChar()
end)
2 Likes

this works but how would i make it so like, the respawn time is inf, but when u press a button it respwans u instantly, so how would i make it so this thing happens when u press the button

1 Like

disabled the “CharacterAutoLoads” property of game.Players, and whenever u wanna spawn the character, just do “Player:LoadCharacter()”

1 Like

i have already done that with a respawn button im just saying how to do this camera thing when u press the button and load character

1 Like

bcuz @Veexas rn when i press the button i edit the script to do the function when u press it, but it justs load character without the camera thingy

1 Like

keep the camera.cameratype = Enum.CameraType.Scriptable until u successfully tweened it into the character

1 Like

i gave u the script, it will tween the camera cframe to ur character’s cframe tweening is smooth version of changing property values with given tweeninfo

1 Like

The script i gave u should be in a LocalScript inside the client’s stuff such as StarterPlayerScript, it will automatically do the animation for u whenever ur character loads, u dont need to change it, whenever ur server decides to load ur character when u press the button, the animation begins

1 Like

rn its a local script in the respawn button like this but if i respawn, the camera becomes scriptable but it does not tween:

local LPlr = game.Players.LocalPlayer
local MyCam = workspace.CurrentCamera
local TS = game:GetService("TweenService")

local TweenDuration = 3

local JustDied = false

local function SetupChar()
	MyCam.CameraType = Enum.CameraType.Scriptable
	JustDied = true

	if JustDied == true then
		JustDied = false
		local Tween1 = TS:Create(MyCam, TweenInfo.new(TweenDuration, Enum.EasingStyle.Linear), {CFrame = LPlr.Character.Head.CFrame})
		Tween1.Completed:Once(function(state)
			if state == Enum.PlaybackState.Completed then
				MyCam.CameraType = Enum.CameraType.Custom
				MyCam.CameraSubject = LPlr.Character.Humanoid
			end
		end)
		Tween1:Play()
	end
end

script.Parent.MouseButton1Click:Connect(function()
	SetupChar()
end)
1 Like

because u did not use my whole script,

u did not add this:

repeat task.wait() until LPlr.Character
SetupChar()
LPlr.CharacterAdded:Connect(function()
	SetupChar()
end)

like i said earlier, theres nothing u need to do, just spawn ur character using serverscript when button has been activated, the script i gave u is automatic, the only thing u can change in my script is the TweenDuration amount

1 Like

remove this

script.Parent.MouseButton1Click:Connect(function()
	SetupChar()
end)

it will stack up the function and make ur function weird

1 Like

no u see, when the player gets killed by the bigger block, the smaller player actually gets destroyed so it doesnt trigger characteradded like in a good way like heres what happens


1 Like

put the script i gave u into StarterPlayerScript, idk if that “DeathGui” have “ResetOnSpawn” property enabled which destroys the script and replace it with new

1 Like

it has resetonspawn bcuz if i turn it off um the camera doesnt work and the gui doesnt destroy

also in the Tween

		local Tween1 = TS:Create(MyCam, TweenInfo.new(TweenDuration, Enum.EasingStyle.Linear), {CFrame = LPlr.Character.Head.CFrame})

change the LPlr.Character.Head.CFrame into LPlr.Character.PrimaryPart.CFrame

turns out ur character doesnt have head, but i assume it atleast have PrimaryPart property value