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

Can someone guide me toward a fix on my Camera.CFrame lerping script?

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

local PlayerGui = Player.PlayerGui



repeat wait()
	Camera.CameraType = Enum.CameraType.Scriptable
until
Camera.CameraType == Enum.CameraType.Scriptable

Camera.CFrame = workspace.CameraPart.CFrame

if script.Parent.CameraValue.Value == 1 then
	PlayerGui.CameraUI.ScreenGuiForward.Enabled = true
	PlayerGui.CameraUI.ScreenGuiBackward.Enabled = true
	PlayerGui.CameraUI.ScreenGuiForward2.Enabled = false
	PlayerGui.CameraUI.ScreenGuiBackward2.Enabled = false
end

if script.Parent.CameraValue.Value == 2 then
	PlayerGui.CameraUI.ScreenGuiForward.Enabled = false
	PlayerGui.CameraUI.ScreenGuiBackward.Enabled = false
	PlayerGui.CameraUI.ScreenGuiForward2.Enabled = true
	PlayerGui.CameraUI.ScreenGuiBackward2.Enabled = true
end

script.Parent.ScreenGuiForward.ForwardBttn.MouseButton1Down:Connect(function()
	script.Parent.CameraValue.Value = 2
	for i = 0,1,0.01 do
		workspace.CameraPart.CFrame:Lerp(workspace.CameraDestinations.CameraDes2.CFrame, i)
		wait()
	end	
end)

script.Parent.ScreenGuiBackward2.BackwardBttn.MouseButton1Down:Connect(function()
	script.Parent.CameraValue.Value = 1
	for i = 0,1,0.01 do
		workspace.CameraPart.CFrame:Lerp(workspace.CameraDestinations.CameraDes1.CFrame, i)
		wait()
	end	
end)

(This is a local script)

This a script I made for a camera that lerps back and fourth between parts on GUI press.

I'll run over what the code is SUPPOSED to do and what I did. First I have a wait loop for making the camera scriptable. Then, I define the players camera CFrame to the CameraPart's CFrame. I create an if statement of a IntValue I have set up in PlayerGui. If the int value == 1, then the Gui for to the second cam appears and the one lerping to the first disappears. The opposite occurs if the IntValue == 2. I then have a function that lerps the camera to the second destination(The destination is a transparent part). I also have another one that only happens when the backward button that is enabled when the IntValue == 2. This lerps back to the original position, the transparent part CameraDes1. The ForwardGui function also turns the IntValue to 2, and the opposite happens with the other function.

For some reason this does not work at all. All it does is change the IntValue to 2. Even if I hit the backwards button to change it back to one, and the lerping does not work at all. But the camera's CFrame does go to the CFrame of the CameraPart.

Is there something I'm doing wrong? I've searched for days.

Keep in mind I'm a beginner scripter and it might be a glaringly obvious error. I'm sorry if this is the case.

Thank you! :)

1 comment

1 answer

✓ Accepted answer

Not an actual answer, just simplified code (please ignore this)

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

local PlayerGui = Player.PlayerGui

Camera.CameraType = Enum.CameraType.Scriptable

Camera.CFrame = workspace.CameraPart.CFrame

if script.Parent.CameraValue.Value == 1 then
    PlayerGui.CameraUI.ScreenGuiForward.Enabled = true
    PlayerGui.CameraUI.ScreenGuiBackward.Enabled = true
    PlayerGui.CameraUI.ScreenGuiForward2.Enabled = false
    PlayerGui.CameraUI.ScreenGuiBackward2.Enabled = false
end

if script.Parent.CameraValue.Value == 2 then
    PlayerGui.CameraUI.ScreenGuiForward.Enabled = false
    PlayerGui.CameraUI.ScreenGuiBackward.Enabled = false
    PlayerGui.CameraUI.ScreenGuiForward2.Enabled = true
    PlayerGui.CameraUI.ScreenGuiBackward2.Enabled = true
end

script.Parent.ScreenGuiForward.ForwardBttn.MouseButton1Down:Connect(function()
    script.Parent.CameraValue.Value = 2
    for i = 0,1,0.01 do
        workspace.CameraPart.CFrame:Lerp(workspace.CameraDestinations.CameraDes2.CFrame, i)
        wait()
    end 
end)

script.Parent.ScreenGuiBackward2.BackwardBttn.MouseButton1Down:Connect(function()
    script.Parent.CameraValue.Value = 1
    for i = 0,1,0.01 do
        workspace.CameraPart.CFrame:Lerp(workspace.CameraDestinations.CameraDes1.CFrame, i)
        wait()
    end 
end)

Could you please turn "script.Parent.CameraValue.Value" into a BoolValue? (and if you would like, rename CameraValue into FirstGuiEnabled) It would make this a lot easier

2 comments

0

Oh, ok! I'll do that!

0

Although I am a bit worried becuase of the fact that I am going to make more lerps later on, and a bool value won't do that.

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