Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Camera not resetting to the player?

Asked by 4 years ago
Edited 4 years ago

Im really new to scripting in roblox studio and I need alot of help. Im using a code to set the camera to a part for a main menu backround. Im trying to make the script so when i press a GUI button it resets the camera angle back to the player. Here is my code so far:

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

repeat wait()
    Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = workspace.CameraPart.CFrame

(For the Camera going to the part, in my local script for my entire main menu)

script.Parent.MouseButton1Click:Connect(function()
    workspace.CurrentCamera.CameraSubject = player.Character.Humanoid
end)

(For the GUI Button Press, its in the local script inside of the textbutton)

I get this error when i press the GUI button:

15:24:41.104 - Players.TheWinterSoilder551.PlayerGui.Main Menu.Sidebar.Play.Play Script:3: attempt to index nil with 'Character'

I really dont know how to fix it.

0
Mind putting the code in code blocks? Qariter 110 — 4y
0
Again im new, how do i do that? TheWinterSoilder551 0 — 4y
0
Try editing then clicking the lua button during editing. Qariter 110 — 4y
0
There you go TheWinterSoilder551 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Your error is just returning that it's not finding the player's character, so I believe you can fix the first script with this:

local plr = game.Players.LocalPlayer
local Character = plr:FindFirstChild("Character")
local Camera = workspace.CurrentCamera

repeat wait()
    Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = workspace.CameraPart.CFrame

And for the other script, which could also be returning the error, try using this:

script.Parent.MouseButton1Click:Connect(function()
workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer:FindFirstChild("Character"):FindFirstChild("Humanoid")
end)

For some reason, it split into two lines... try placing "workspace.CurrentCamera.CameraSubect = " and the 'game.Players.LocalPlayer:WaitForChild("Character"):FindFirstChild("Humanoid")' into one line.

0
ok thank you TheWinterSoilder551 0 — 4y
0
now the camera doesnt go to the part i want it to, it goes to the player automatically TheWinterSoilder551 0 — 4y
0
Now im getting this error: 17:15:44.633 - Infinite yield possible on 'Players.TheWinterSoilder551:WaitForChild("Character")' TheWinterSoilder551 0 — 4y
0
I edited the thing, see if the 'Infinite yield' still shows up. YAYAYGPPR 82 — 4y
View all comments (4 more)
0
ok TheWinterSoilder551 0 — 4y
0
oh new error: 17:36:41.065 - Players.TheWinterSoilder551.PlayerGui.Main Menu.Sidebar.Play.Play Script:2: attempt to index nil with 'FindFirstChild' TheWinterSoilder551 0 — 4y
0
Is 'Play Script' a localscript? Because it isn't finding the LocalPlayer for some reason. YAYAYGPPR 82 — 4y
0
Yea it is TheWinterSoilder551 0 — 4y
Ad

Answer this question