Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I destroy and then reset the camera to the Character?

Asked by
uhjos_h 19
3 years ago
Edited 3 years ago

Hi!

So basically, I was wondering how I would be able to use :destroy() on the camera, and then make a new one (locally) once the player's humanoid health is at 0.

Any help?

This is a LocalScript:

local button = script.Parent
local cam = game.Workspace.CurrentCamera
shared.camRotate = false

button.MouseButton1Down:Connect(function()
    wait(4.5)
    cam.CameraSubject =  game.Players.LocalPlayer.Character.Humanoid
    cam.CameraType = "Custom"
    shared.camRotate = true
    game.StarterGui.LocalScript:Destroy()
    game.Workspace.CamPart:Destroy()
end)

if game.Players.LocalPlayer.Character.Humanoid.Health == 0 then
    cam:Destroy()
    wait(6)
    local x = Instance.new("Camera")
    x.Name = "CurrentCamera"
    x.CameraSubject =  game.Players.LocalPlayer.Character.Humanoid
    x.CameraType = "Custom"
end

Heres the script which adjusts the camera on spawn:



local Camera = game.Workspace.CurrentCamera local Player = game.Players.LocalPlayer repeat wait() until Player.Character Camera.CameraType = "Scriptable" Camera.CFrame = game.Workspace.CamPart.CFrame script.Parent.Enabled = true

Is there any way to reset the camera to default after a player clicks a button or with wait()?

0
May I ask why you want to make a new Camera? Resetting the Camera to default is more convenient. Bankrovers 226 — 3y
0
And if you delete a Camera, a new one is automatically created. So you don't have to do this yourself. Bankrovers 226 — 3y
0
I am trying to make a new camera once I delete it because it switches to Scriptable once you reset due to the LocalScript which switches it to Scriptable even if you use :destroy() uhjos_h 19 — 3y

2 answers

Log in to vote
0
Answered by
2_MMZ 1059 Moderation Voter
3 years ago

It's not recommended to make a new camera. You should reset the Camera to its default property. Making a new camera doesn't help you with this, and the resetting camera solution is much easier. I'm also noticing that you're trying to change the CameraType with cam.CameraType = "Custom", this could be an error. Instead, try cam.CameraType = Enum.CameraType.Custom.

0
This still did not work, any idea at all? And does the LocalScript need to be in a specific folder? uhjos_h 19 — 3y
Ad
Log in to vote
0
Answered by
pwx 1581 Moderation Voter
3 years ago

Change the CameraType to custom and CameraSubject back to the humanoid, like so:

local Players = game:GetService('Players')
local Player = Players.LocalPlayer
local Cam = workspace.CurrentCamera
local Character = Player.Character or Player.CharacterAdded:Wait()

Cam.CameraType = Enum.CameraType.Custom
Cam.CameraSubject = Character:WaitForChild('Humanoid')

Answer this question