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.
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.