Hello. So I have this “habit” of storing any camera/gui related LocalScripts inside of StarterGui, character related LocalScripts in StarterCharacterScripts and player related LocalScripts inside of StarterPlayerScripts.
Most of them work, but today I made a script that tweens the camera’s cframe to a part in the workspace, waits a few seconds, and then tweens the camera back to the player and since it’s related to the camera, I put it inside of StarterGui.
The issue is, if the player respawns while those few seconds of waiting are in progress, the script does not tween the camera back to the player’s head’s CFrame, but just stays in place. Same happens for a script that I have in StarterGui, which makes the player’s camera tilt 30 degrees when they’re damaged, but if they respawn while the tween for the tilt is happening, the camera stays tilted until the player rejoins.
I’ve seen someone post something like this before, and their solution stated, that they moved their script from StarterGui to StarterCharacterScripts and it worked even if the player died during the “cutscene”, so I tried that, but there’s the same results. Same happens for StarterPlayerScripts. How could I possibly fix that and make the code run regardless of the player respawning?
Where did you put the script? Literally inside a ScreenGUI or inside a StarterGUI, StarterCharacterScripts or StarterPlayerScripts?
If it’s inside a ScreenGui you can try disabling ResetOnSpawn.
If it’s inside StarterGUI, StarterCharacterScripts or StarterPlayerScripts you may send the script itself so I can see what’s the problem. You’re free to send
okay, it seems to have fixed the issue, but since the spawnlocations are random in my game, once the camera tweens back to the new character’s head location, it switches back to old one’s head location and it gets stuck there
i could try respawning, but an average player isn’t gonna know that + resetting is going to be disabled in my game
for characters its best to set camera subject to their humanoids, i have no clue where does camera decide to be since its a humanoid but you can try making another temporal camera which will have new character’s humanoid as subject and get it’s position in order to tween to it seamlessly
it does work and puts the camera in the position of the new character and moves with it, it works like a regular camera, but the character does not turn with the camera + this is what the camera looks like:
uhh i didnt do that, no, this is the code that i used:
local plr = game.Players.LocalPlayer
local TS = game:GetService("TweenService")
game.ReplicatedStorage.round_storage.remote_events.camera_show_monster_spawn.OnClientEvent:Connect(function()
if plr:WaitForChild("PlayerGui"):WaitForChild("main_menu_gui"):WaitForChild("inMainMenu").Value == false then
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera.CameraSubject = nil
TS:Create(workspace.CurrentCamera, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {CFrame = workspace.monsters.monster_spawn_cam.CFrame}):Play()
task.wait(4)
TS:Create(workspace.CurrentCamera, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {CFrame = plr.Character.Head.CFrame}):Play()
task.wait(0.9)
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
workspace.CurrentCamera.CameraSubject = workspace[plr.Name].Head
else
print("camera_show_monster_spawn failed, player in main menu")
end
end)
i used the new character with the same playername so it uses the new character instead of using the plr.Character variable, since that refers to the old character i suppose
im really sorry, im a relatively new scripter
wait so what is it supposed to do? when a round begins make everyone look at the player whos the monster? im a bit confused. Also by the way you can have spaces in names of instances you’d like to reference in code, just keep them readable and do something like this
so once the round starts, the camera tweens towards the spawnpoint of the monsters, waits for the monsters to spawn and then tween back to the players head and once it reaches the head, it changes the Enum.CameraType.Custom so that the camera goes back to normal and works like Roblox coded it (the default first person) for a nice transition
i also could just ignore the probabilities of someone dying without a monster in the workspace + without resetting since it’s disabled and not be worried about that
So I made it work but it needs to be adapted to your environment. For some reason, other than player’s cameras just stop existing when playing, so you need a CFrame.
local lp = game.Players.LocalPlayer
local char = lp.Character or lp.CharacterAdded:Wait() -- :Wait() waits until event fires and additionally returns whatever the event returns if saved into a variable
local cam = workspace.CurrentCamera
local tweenSvc = game.TweenService
game.ReplicatedStorage.Remotes.roundStart.OnClientEvent:Connect(function()
task.wait(3)
char.HumanoidRootPart.Anchored = true
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
local oldCameraCF = cam.CFrame
local toMonster = tweenSvc:Create(workspace.CurrentCamera, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {CFrame = workspace.dummy.HumanoidRootPart.CFrame})
toMonster:Play()
toMonster.Completed:Wait()
task.wait(3)
local backToPlayer = tweenSvc:Create(workspace.CurrentCamera, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {CFrame = oldCameraCF})
backToPlayer:Play()
backToPlayer.Completed:Wait()
char.HumanoidRootPart.Anchored = false
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
end)
You’ll have to anchor the player so when the camera returns they’re aligned perfectly. Offtopic but I’d rather make the camera teleport back and forth with fading to black instead of fixing those alignment issues like this xD