I have this script that when it is clicked, it changes between a part CFrame and the CurrentCamera (Origin) of the player.
So there is a problem, the script works ONCE and then stops working.
Iāve already tried using a normal Script in StarterGUI and Workspace, Iāve tried using a LocalScript in StarterGUI and Workspace, Iāve tried leaving the Script and LocalScript inside the model, Iāve tried all the available options to try to fix the problem, and I havenāt been able to. resolve it.
I even resorted to Artificial Intelligence, but even it was unable to solve the problem.
Iām desperate to fix this problem, and I hope you can help me.
Thank you in advance for your attention, have a great day!
The LocalScript is located at StarterGUI
local camera = workspace.CurrentCamera
local camLocked = false
local originalCFrame = camera.CFrame
-- Alternating cameras
local function ToggleCameraLock()
if not camLocked then
-- Lock camera pos at Cam1
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = workspace.ZoomSystem.Cam1.CFrame
camLocked = true
else
-- Unlock camera and restore Original CFrame
camera.CameraType = Enum.CameraType.Custom
camera.CFrame = originalCFrame
camLocked = false
end
end
-- Connect MouseClick event to ToggleCameraLock function
local clickDetector = workspace.ZoomSystem:FindFirstChild("ClickZoom") and workspace.ZoomSystem.ClickZoom:FindFirstChild("ClickDetector")
if clickDetector then
clickDetector.MouseClick:Connect(ToggleCameraLock)
else
warn("Click detector not found!")
end
After setting camera back to custom, you also need to set the CameraSubject back to playerās humanoid. There is no need to set the CFrame, as this will be automatically adjusted with the internal camera script.
-- Unlock camera and restore Original CFrame
camera.CameraType = Enum.CameraType.Custom
camera.CameraSubject = game.Players.LocalPlayer.Character:FindFirstChildOfClass("Humanoid")
--camera.CFrame = originalCFrame
camLocked = false
None of your suggestions work, sorry for wasting your time
Changing the subject, I got scripts that can manipulate the camera! But the script that enables / disables it is not able to āfindā (I think) the scripts inside the player.
StarterPack
Player inventory (on game)
Enable / Disable LocalScript
local clickDetector = script.Parent
local lockScript = game.Players.LocalPlayer.Backpack.Lock
local unlockScript = game.Players.LocalPlayer.Backpack.Unlock
local Locked = script.Parent.Parent.Locked
Locked = false
clickDetector.MouseClick:Connect(function()
if Locked == false and lockScript.Disabled == true then
Locked = true
lockScript.Disabled = false
unlockScript.Disabled = true
elseif Locked == true and lockScript.Disabled == false then
Locked = false
lockScript.Disabled = true
unlockScript.Disabled = false
end
end)
I need LocalScript to be able to enable / disable scripts
I hope you can help me! Thanks
Why you just donāt turn off or turn on script when u need change the camera? Do you try change camera subject or set camera CFrame same as target CFrame?
Disabling and re-enabling scripts is generally a bad practice. For example, disabling a script, WILL NOT disconnect connections that this script has made.
Which may be a reason that your script does not work. After enabling Lock script, you now how 2 active connections and they might be both toggling the the camera, leaving the result the same.
One final check, trivial I know, but are you sure that the ClickDetector is within reach and view after the camera switch? That is, does the mouse cursor changes to the āPoinging fingerā icon? If not, you may want to increase the MaxActivationDistance property.