Refresh Command Camera Angle Fix

  1. What do you want to achieve?

Refresh Command Camera angle to stay the same when a player refreshes their character!

  1. What is the issue?

https://gyazo.com/8e79e3616fa341d8fa58d2a9f138d5c1

Camera angle is being set back to default.

  1. What solutions have you tried so far?

I tried a different way of loading character, but still no fix.

function Refresh.Refresh(player)
	
	if player.Character == nil then
		warn("Character does not exist")
		return
	end
	
	pcall(function()
		local Pos = player.Character:GetPrimaryPartCFrame() -- getting OG position
		player:LoadCharacter() -- refreshing character
		player.Character:SetPrimaryPartCFrame(Pos) -- setting new position
		if player.Character:FindFirstChild("ForceField") then -- destroying forcefield
			player.Character["ForceField"]:Destroy()
		end
	end)
	
end

For this, I would use :FireClient, save the CFrame of the camera, and change the CFrame back when the character is refreshed.

function Refresh.Refresh(player)
	
	if player.Character == nil then
		warn("Character does not exist")
		return
	end
	
	pcall(function()
		local event = game.ReplicatedStorage.RefreshEvent
		event:FireClient(player)
		local Pos = player.Character:GetPrimaryPartCFrame() -- getting OG position
		task.wait() --to give the client some time to get the angle
		player:LoadCharacter() -- refreshing character
		player.Character:SetPrimaryPartCFrame(Pos) -- setting new position
		if player.Character:FindFirstChild("ForceField") then -- destroying forcefield
			player.Character["ForceField"]:Destroy()
		end
	end)
	
end

LocalScript

game.ReplicatedStorage.RefreshEvent.OnClientEvent:Connect(function()
	local angle = workspace.Camera.CFrame
	game.Players.LocalPlayer.CharacterAdded:Wait()
	workspace.Camera.CFrame = angle
end)

I put local script into, StarterGui is that correct?

It seems to not really change anything?

You can put the script into StarterGui or StarterPlayerScripts. Are there any errors coming from the output?

No errors.

It tends to just, refresh the player of course… Then if they player is facing a certain way, it will refresh camera back to the fov default.

Before :

image

After :

image

Alright, I figured out the problem. The local script doesn’t give the character enough time to load. So, I added a task.wait() to it.

game.ReplicatedStorage.RefreshEvent.OnClientEvent:Connect(function()
	local angle = workspace.Camera.CFrame
	game.Players.LocalPlayer.CharacterAdded:Wait()
	task.wait(0.02) --this changes the camera angle at the perfect time
	workspace.Camera.CFrame = angle
end)
1 Like

Your amazing.

Would have never came up with the task.wait()

Thank you!