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)
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)