Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

disable manipulated or customized camera?

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

2 comments

1

You have to untie the Functions by writing :Disconnect()

0

@Feahren I dont uderstand

1 answer

✓ Accepted answer

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)

6 comments

0

Script work!,but when the camera follows the character (the head) the camera looks weird, you can not even control

0

Use enums pls

0

It's the same

0

@ksony, if you want to be able to always control the camera, just remove the sections relating to "CameraType" under the functions (but not the first time it is written in the code), I've edited the answer to do this

0

I already solved it, it was the while true do. I made 2 scripts, thanks for your help

0

ah, alright, no problem

This discussion is preserved as it was. New answers, comments, and votes are closed.