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

Camera Manipulation with Filtering?

Asked by 9 years ago

Why doesn't this code work with FilteringEnabled? It works when you join the game, then when you die and respawn, it doesn't work anymore.

repeat wait() until game:GetService("Players").LocalPlayer

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Timer = ReplicatedStorage:WaitForChild("Timer")
local MapHolder = workspace:WaitForChild("MapHolder")
local SelectedMap = ReplicatedStorage:WaitForChild("SelectedMap")
local Playing = Player:WaitForChild("Playing")

local CurrentCamera = workspace.CurrentCamera

Angle = 0
while wait() do
    if Timer.Value > 0 and Playing.Value == false and Character:FindFirstChild("Humanoid") and Character:FindFirstChild("Humanoid").Health > 0 then
        CurrentCamera.CameraSubject = MapHolder:FindFirstChild(SelectedMap.Value):FindFirstChild("PartCAM")
        CurrentCamera.CoordinateFrame = CFrame.new(MapHolder:FindFirstChild(SelectedMap.Value):FindFirstChild("PartCAM").Position) * CFrame.Angles(0, Angle, 0) * CFrame.new(0, 0, -25)
    elseif Timer.Value < 0 and Playing.Value == false and Character:FindFirstChild("Humanoid") and Character:FindFirstChild("Humanoid").Health > 0 then
        CurrentCamera.CoordinateFrame = CFrame.new(workspace.Scene:FindFirstChild("PartCAM").Position) * CFrame.Angles(0, Angle, 0) * CFrame.new(0, 0, -10)
        CurrentCamera.CameraSubject = workspace.Scene:FindFirstChild("PartCAM")
    elseif Timer.Value > 0 and Playing.Value == true and Character:FindFirstChild("Humanoid") and Character:FindFirstChild("Humanoid").Health > 0 then
        CurrentCamera.CameraSubject = Character:FindFirstChild("Humanoid")
    end
    Angle = Angle + math.rad(0.5)
end
0
So hard to read....Consider using more variables.... NotsoPenguin 705 — 9y
0
So this helps me with my issue.. how? peoplemove12 148 — 9y
0
It helps with legibility. You have a lot of repeated code. ex, instead of having 'Character:FindFirstChild("Humanoid")' 7 times, just have it once between lines 14 and 15 as 'local humanoid = Character:FindFirstChild("Humanoid")' and 'if humanoid and humanoid.Health > 0 then --[[lines 15-23 here]] end". Same idea with PartCAM. Also, this script doesn't manage the player respawning; what does? chess123mate 5873 — 9y

Answer this question