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

How do I make the camera follow the player after causing it to be fixed?

Figured I may need to rephrase the question.

The script I have which creates the title screen and fixes the camera in one position works, but I don't know how to return the camera to the default parameters after the player presses Start. Help would be appreciated!

a header

Script:

--[[ Player ]]
local player = game.Players.LocalPlayer
player.Character.Humanoid.WalkSpeed = 0

--[[ Fixed Camera ]]
local cam = workspace.CurrentCamera
local CameraLocation = Vector3.new(-22.5, 35.5, -58.5)
local CameraDirection = Vector3.new(-8, 4.5, -92)

cam.CameraType = "Scriptable"

game["Run Service"].RenderStepped:connect(function()
	cam.CoordinateFrame = CFrame.new(CameraLocation,CameraDirection)
end)


--[[ Title Screen ]]
local titlescreen = Instance.new("ScreenGui")
titlescreen.Parent = script.Parent
titlescreen.Name = "TitleScreen"

-- Frame
local titleframe = Instance.new("Frame")
titleframe.Name = "TitleFrame"
titleframe.Parent = titlescreen
titleframe.Position = UDim2.new(0.08, 0, 0, 0)
titleframe.Size = UDim2.new(.85, 0, .85, 0)
titleframe.Style = "RobloxRound"

-- Text
local titletext = Instance.new("TextLabel")
titletext.Name = "TitleText"
titletext.Parent = titlescreen
titletext.TextColor3 = Color3.new(170, 0, 0)
titletext.Position = UDim2.new(0.4, 0, 0.085, 0)
titletext.Size = UDim2.new(0, 250, 0, 50)
titletext.FontSize = "Size24"
titletext.BackgroundTransparency = 1
titletext.Text = "Project Undefined"

-- Button
local titlebutton = Instance.new("TextButton")
titlebutton.Name = "TitleButton"
titlebutton.Parent = titlescreen
titlebutton.Position = UDim2.new(0, 400, 0, 175)
titlebutton.Size = UDim2.new(0, 250, 0, 50)
titlebutton.BackgroundColor3 = Color3.new(144, 0, 0)
titlebutton.FontSize = "Size14"
titlebutton.Text = "Start"


-- MouseClick
function onClicked()
    titlescreen:Destroy()
	player.Character.Humanoid.WalkSpeed = 16
	cam.CameraSubject = player.Character.Humanoid
	cam.CameraType = "Custom"
end

titlebutton.MouseButton1Down:connect(onClicked)

Thanks in advance!

EDIT: Full script in case it's needed.

1 answer

✓ Accepted answer
--[[ Player ]]
local player = game.Players.LocalPlayer
player.Character.Humanoid.WalkSpeed = 0

--[[ Fixed Camera ]]
local cam = workspace.CurrentCamera
local CameraLocation = Vector3.new(-22.5, 35.5, -58.5)
local CameraDirection = Vector3.new(-8, 4.5, -92)

cam.CameraType = "Scriptable"
local start == false -- debouncer
game["Run Service"].RenderStepped:connect(function()
	 if start == false then -- breaks it on click
    cam.CoordinateFrame = CFrame.new(CameraLocation,CameraDirection)
	end
end)


--[[ Title Screen ]]
local titlescreen = Instance.new("ScreenGui")
titlescreen.Parent = script.Parent
titlescreen.Name = "TitleScreen"

-- Frame
local titleframe = Instance.new("Frame")
titleframe.Name = "TitleFrame"
titleframe.Parent = titlescreen
titleframe.Position = UDim2.new(0.08, 0, 0, 0)
titleframe.Size = UDim2.new(.85, 0, .85, 0)
titleframe.Style = "RobloxRound"

-- Text
local titletext = Instance.new("TextLabel")
titletext.Name = "TitleText"
titletext.Parent = titlescreen
titletext.TextColor3 = Color3.new(170, 0, 0)
titletext.Position = UDim2.new(0.4, 0, 0.085, 0)
titletext.Size = UDim2.new(0, 250, 0, 50)
titletext.FontSize = "Size24"
titletext.BackgroundTransparency = 1
titletext.Text = "Project Undefined"

-- Button
local titlebutton = Instance.new("TextButton")
titlebutton.Name = "TitleButton"
titlebutton.Parent = titlescreen
titlebutton.Position = UDim2.new(0, 400, 0, 175)
titlebutton.Size = UDim2.new(0, 250, 0, 50)
titlebutton.BackgroundColor3 = Color3.new(144, 0, 0)
titlebutton.FontSize = "Size14"
titlebutton.Text = "Start"


-- MouseClick
function onClicked()
    titlescreen:Destroy()
    player.Character.Humanoid.WalkSpeed = 16
	start = true -- fires the debouncer
    cam.CameraSubject = player.Character.Humanoid
    cam.CameraType = "Custom"
end

titlebutton.MouseButton1Down:connect(onClicked)


1 comment

1

#annotatednohate

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