As you can see, the camera goes to some random position, why does this happen?
By the way the player is respawned using :LoadCharacter()
Did you also disable characterautoloads?
Can you take screenshot of the codes which get character respawned ?
Not sure, let me check.
it wasn’t, now let’s see if that fixes the bug.
Nope did not fix the issue
LocalScript that handles the camera when the player dies:
local cs = game:GetService("CollectionService")
wait(3)
local Parts = cs:GetTagged("DeathRegion")
local functions = {}
local db = false
local function PseudoDeath(Otherpa)
if db == false then
db = true
if game:GetService("Players"):GetPlayerFromCharacter(Otherpa.Parent) == game.Players.LocalPlayer then
local player = game:GetService("Players"):GetPlayerFromCharacter(Otherpa.Parent)
player.Character.CameraOffset:Destroy()
for i = 1 , 50 do
local t = game:GetService("TweenService"):Create(workspace.CurrentCamera , TweenInfo.new(0.01) , {CFrame = CFrame.new(workspace.CurrentCamera.CFrame.Position , game.Players.LocalPlayer.Character.PrimaryPart.Position)})
t:Play()
t.Completed:Wait()
end
game:GetService("TweenService"):Create(game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame , TweenInfo.new(0.2) , {BackgroundTransparency = 0}):Play()
wait(1)
game.ReplicatedStorage.RespawnCharacter:FireServer()
player.CharacterAdded:Wait()
game:GetService("TweenService"):Create(game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").Frame , TweenInfo.new(0.2) , {BackgroundTransparency = 1}):Play()
end
db = false
end
end
for i , v in pairs(Parts) do
v.Touched:Connect(PseudoDeath)
end
Remote event script that respawns player:
game.ReplicatedStorage.RespawnCharacter.OnServerEvent:Connect(function(Player)
Player:LoadCharacter()
end)
Both of these work normally until i run this function locally:
local function SetCustomCamera(Otherpart)
if game:GetService("Players"):GetPlayerFromCharacter(Otherpart.Parent) == game.Players.LocalPlayer then
workspace.CurrentCamera.CameraType = Enum.CameraType.Fixed
workspace.CurrentCamera.CameraType = Enum.CameraType.Watch
end
end
for i , v in pairs(CustomCameraParts) do
v.Touched:Connect(function(otherPart)
SetCustomCamera(otherPart)
end)
end
At which point the error ocurrs, only if the player has touched a death region at least once, otherwise it works as expected
Try this:
game.ReplicatedStorage.RespawnCharacter.OnServerEvent:Connect(function(Player)
camera.CameraSubject = character.Humanoid
end)
Ok, will try it out
Now the character doesn’t respawn lol, the error happens when the camera’s type changes after dying once.
Try this in your local script which handles the camera when the player dies :
local cs = game:GetService(“CollectionService”)
wait(3)
local Parts = cs:GetTagged("DeathRegion")
local functions = {}
local db = false
local function PseudoDeath(Otherpa)
if db == false then
db = true
if game:GetService("Players"):GetPlayerFromCharacter(Otherpa.Parent) == game.Players.LocalPlayer then
local player = game:GetService("Players"):GetPlayerFromCharacter(Otherpa.Parent)
player.Character.CameraOffset:Destroy()
spawn(function()
for i = 1 , 50 do
local t = game:GetService("TweenService"):Create(workspace.CurrentCamera , TweenInfo.new(0.01) , {CFrame = CFrame.new(workspace.CurrentCamera.CFrame.Position , game.Players.LocalPlayer.Character.PrimaryPart.Position)})
t:Play()
t.Completed:Wait()
end
end)
game:GetService("TweenService"):Create(game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame , TweenInfo.new(0.2) , {BackgroundTransparency = 0}):Play()
wait(1)
game.ReplicatedStorage.RespawnCharacter:FireServer()
player.CharacterAdded:Wait()
game:GetService("TweenService"):Create(game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").Frame , TweenInfo.new(0.2) , {BackgroundTransparency = 1}):Play()
end
db = false
end
end
for i , v in pairs(Parts) do
v.Touched:Connect(PseudoDeath)
end
also this is for the script which respawn player
game.Players.CharacterAutoLoads = false
game.ReplicatedStorage.RespawnCharacter.OnServerEvent:Connect(function(Player)
Player:LoadCharacter()
end)
Fixed it already, turns out i did not set the camera subject after manualy reloading the character, but thanks.