Hello, my problem is that I can not disable the personalized camera that I place, once it is activated it remains that way forever My script to disable and enable camera :
local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Camera = workspace.CurrentCamera function s1() script.Parent.camera.Disabled = false end function s2() Camera.CameraType = Enum.CameraType.Fixed script.Parent.camera.Disabled = true end game.ReplicatedStorage.Cam.OnClientEvent:Connect(s1) game.ReplicatedStorage.Cam2.OnClientEvent:Connect(s2)
the camera script :
local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Camera = workspace.CurrentCamera while true do Camera.CameraType = Enum.CameraType.Scriptable Camera.CFrame = workspace.CameraPart.CFrame wait(0) end
As you see the first script, i try this: Camera.CameraType = Enum.CameraType.Fixed but it does not work
Since these are both LocalScripts, and you only have one loop, you don't even need two scripts, you can simply combine them.
To change the CameraType, you can simply define the string, rather than write the "Enum"
The while true do loop requires a wait time (using wait(0) may break the script)
You can immediately connect the function when you define it.
The player's Character's Head is the default CFrame, so when the loop is disabled, this is what should be the new setting
local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Camera = workspace.CurrentCamera script.BoolValue.Value = true game.ReplicatedStorage.Cam.OnClientEvent:Connect(function() script.BoolValue.Value = true end) game.ReplicatedStorage.Cam2.OnClientEvent:Connect(function() script.BoolValue.Value = false end) while true do if script.BoolValue.Value = true then Camera.CameraType = "Scriptable" Camera.CFrame = workspace.CameraPart.CFrame else -- Default Settings Camera.CameraType = "Custom" Camera.CFrame = Character.Head.CFrame end wait() end
If you add a "BoolValue" -- in this case simply named "BoolValue" under the script, this will keep the loop in check --- this example has the Bool Automatically set to true.
Otherwise, if you want the loop to be broken, you can add a conditional event where upon being set by the Cam2 Client Event, the loop will break, if using the above script, you would add it under the "else" condition. This will make sure that the loop will not be run again, ever.
local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Camera = workspace.CurrentCamera script.BoolValue.Value = true game.ReplicatedStorage.Cam.OnClientEvent:Connect(function() script.BoolValue.Value = true end) game.ReplicatedStorage.Cam2.OnClientEvent:Connect(function() script.BoolValue.Value = false end) while true do if script.BoolValue.Value = true then Camera.CameraType = "Scriptable" Camera.CFrame = workspace.CameraPart.CFrame else -- Default Settings Camera.CameraType = "Custom" Camera.CFrame = Character.Head.CFrame break end wait() end
You can also change your loop to be a repeat loop based on a value or event
local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Camera = workspace.CurrentCamera script.BoolValue.Value = true wait() game.ReplicatedStorage.Cam.OnClientEvent:Connect(function() script.BoolValue.Value = true end) game.ReplicatedStorage.Cam2.OnClientEvent:Connect(function() script.BoolValue.Value = false end) repeat Camera.CameraType = "Scriptable" Camera.CFrame = workspace.CameraPart.CFrame wait() until script.BoolValue.Value = false -- When the loop stops, the camera defaults are reset Camera.CameraType = "Custom" Camera.CFrame = Character.Head.CFrame
However, you can also just set the settings of the camera without the loop at all like so:
local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Camera = workspace.CurrentCamera local part = workspace:WaitForChild("CameraPart") Camera.CameraType = "Scriptable" Camera.CFrame = part.CFrame game.ReplicatedStorage.Cam.OnClientEvent:Connect(function() Camera.CameraType = "Scriptable" Camera.CFrame = workspace.CameraPart.CFrame end) game.ReplicatedStorage.Cam2.OnClientEvent:Connect(function() Camera.CameraType = "Custom" Camera.CFrame = Character.Head.CFrame end)
EDIT: Comment #1, Keeping the Camera Scriptable
Remove the sections pertaining to "CameraType" but not at the beginning of the code, which changed the Type from "Custom" to "Scriptable". This can be seen below:
local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Camera = workspace.CurrentCamera local part = workspace:WaitForChild("CameraPart") Camera.CameraType = "Scriptable" Camera.CFrame = part.CFrame game.ReplicatedStorage.Cam.OnClientEvent:Connect(function() Camera.CFrame = workspace.CameraPart.CFrame end) game.ReplicatedStorage.Cam2.OnClientEvent:Connect(function() Camera.CFrame = Character.Head.CFrame end)