local Button = script.Parent.ImageButton
local On = false
local CamSubject = game.Workspace.EventCamera
local Camera = game.Workspace.CurrentCamera
local CamCFrame
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local player = game.Players.LocalPlayer
Button.MouseButton1Click:Connect(function()
if On == false then
On = true
Button.Image = "rbxassetid://9133905664"
player.Character.Humanoid.WalkSpeed = 0
player.Character.Humanoid.JumpHeight = 0
CamCFrame = Camera.CFrame
local goal = {}
goal.CFrame = CFrame.new(CamSubject.Position + CamSubject.CFrame.LookVector * -5)
Camera.CameraSubject = CamSubject
Camera.CameraType = Enum.CameraType.Scriptable
game.TweenService:Create(Camera, TweenInfo.new(0.5), goal):Play()
elseif On == true then
On = false
Button.Image = "rbxassetid://9133919388"
player.Character.Humanoid.WalkSpeed = 16
player.Character.Humanoid.JumpHeight = 7.2
local goal = {}
goal.CFrame = CamCFrame
Camera.CameraSubject = nil
game.TweenService:Create(Camera, TweenInfo.new(0.5), goal):Play()
wait(0.5)
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = Character.Humanoid
end
end)
Why not put the CFrame inside the goal table?
maybe something like this: local goal = {CFrame = CFrame.New(CamSubject.Position + CamSubject.CFrame.LookVector * -5)}
local Button = script.Parent.ImageButton
local On = false
local CamSubject = game.Workspace.EventCamera
local Camera = game.Workspace.CurrentCamera
local CamCFrame
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local player = game.Players.LocalPlayer
Button.MouseButton1Click:Connect(function()
if On == false then
On = true
Button.Image = "rbxassetid://9133905664"
player.Character.Humanoid.WalkSpeed = 0
player.Character.Humanoid.JumpHeight = 0
CamCFrame = Camera.CFrame
local goal = {CFrame = CFrame.New(CamSubject.Position + CamSubject.CFrame.LookVector * -5)}
goal.CFrame = CFrame.new(CamSubject.Position + CamSubject.CFrame.RightVector * 0) -- it's either positive 5 or negative. If that doesn't work try UpVector * 5 or negative 5
Camera.CameraSubject = CamSubject
Camera.CameraType = Enum.CameraType.Scriptable
game.TweenService:Create(Camera, TweenInfo.new(1), goal):Play()
elseif On == true then
On = false
Button.Image = "rbxassetid://9133919388"
local goal = {}
goal.CFrame = CamCFrame
Camera.CameraSubject = nil
game.TweenService:Create(Camera, TweenInfo.new(1), goal):Play()
wait(1)
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = Character.Humanoid
player.Character.Humanoid.WalkSpeed = 16
player.Character.Humanoid.JumpHeight = 7.2
end
end)
local Button = script.Parent.ImageButton
local On = false
local CamSubject = game.Workspace.EventCamera
local Camera = game.Workspace.CurrentCamera
local CamCFrame
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local player = game.Players.LocalPlayer
Button.MouseButton1Click:Connect(function()
if On == false then
On = true
Button.Image = "rbxassetid://9133905664"
player.Character.Humanoid.WalkSpeed = 0
player.Character.Humanoid.JumpHeight = 0
CamCFrame = Camera.CFrame
local goal = {CFrame = CFrame.New(CamSubject.Position, CamSubject.CFrame.LookVector * -5)}
Camera.CameraSubject = CamSubject
Camera.CameraType = Enum.CameraType.Scriptable
game.TweenService:Create(Camera, TweenInfo.new(0.5), goal):Play()
elseif On == true then
On = false
Button.Image = "rbxassetid://9133919388"
player.Character.Humanoid.WalkSpeed = 16
player.Character.Humanoid.JumpHeight = 7.2
local goal = {}
goal.CFrame = CamCFrame
Camera.CameraSubject = nil
game.TweenService:Create(Camera, TweenInfo.new(0.5), goal):Play()
wait(0.5)
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = Character.Humanoid
end
end)
local Button = script.Parent.ImageButton
local On = false
local CamSubject = game.Workspace.EventCamera
local Camera = game.Workspace.CurrentCamera
local CamCFrame
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local player = game.Players.LocalPlayer
Button.MouseButton1Click:Connect(function()
if On == false then
On = true
Button.Image = "rbxassetid://9133905664"
player.Character.Humanoid.WalkSpeed = 0
player.Character.Humanoid.JumpHeight = 0
CamCFrame = Camera.CFrame
local goal = CFrame.new(CamSubject.Position + CamSubject.CFrame.LookVector * 20, CamSubject.Position)
Camera.CameraSubject = CamSubject
Camera.CameraType = Enum.CameraType.Scriptable
game.TweenService:Create(Camera, TweenInfo.new(0.5), goal):Play()
elseif On == true then
On = false
Button.Image = "rbxassetid://9133919388"
player.Character.Humanoid.WalkSpeed = 16
player.Character.Humanoid.JumpHeight = 7.2
local goal = {}
goal.CFrame = CamCFrame
Camera.CameraSubject = nil
game.TweenService:Create(Camera, TweenInfo.new(0.5), goal):Play()
wait(0.5)
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = Character.Humanoid
end
end)
local Button = script.Parent.ImageButton
local On = false
local Debounce = false
local CamSubject = game.Workspace.EventCamera
local Camera = game.Workspace.CurrentCamera
local CamCFrame
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local player = game.Players.LocalPlayer
Button.MouseButton1Click:Connect(function()
if Debounce then return end
Debounce = true
if On == false then
On = true
Button.Image = "rbxassetid://9133905664"
player.Character.Humanoid.WalkSpeed = 0
player.Character.Humanoid.JumpHeight = 0
CamCFrame = Camera.CFrame
local goal = {}
goal.CFrame = CFrame.new(CamSubject.Position + CamSubject.CFrame.LookVector * 20, CamSubject.Position)
Camera.CameraSubject = CamSubject
Camera.CameraType = Enum.CameraType.Scriptable
local Tween: Tween = game.TweenService:Create(Camera, TweenInfo.new(0.5), goal)
Tween:Play()
Tween.Completed:Wait()
elseif On == true then
On = false
player.Character.Humanoid.WalkSpeed = 16
player.Character.Humanoid.JumpHeight = 7.2
Button.Image = "rbxassetid://9133919388"
local goal = {}
goal.CFrame = CamCFrame
Camera.CameraSubject = nil
local Tween: Tween = game.TweenService:Create(Camera, TweenInfo.new(0.5), goal)
Tween:Play()
Tween.Completed:Wait()
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = Character.Humanoid
end
Debounce = false
end)
I’ve also added a debounce for script to not break.