Howdy! I’m way new to scripting, but I’m working on a very simple spaceship and I ran into a couple of problems.
For all intents and purposes, I’m using this tutorial made by Roblox. In this series of tutorials, the camera is top down over the player, but I’d like it to follow them similar to how the default one works.
I don’t need it to be adjustable, I just want it to follow the player and turn as they turn, sort of like having a camera on a pole attached to the player.
I’m pretty sure I need to insert a camera attached to an invisible part, but since the model is meant to replace the default roblox character, it’s in StarterPlayer, so it doesn’t work there.
This is the current code I use, it’s in a localscript that I put in StarterPlayerScripts.
local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local Run = game:GetService("RunService")
local player = game.Players.LocalPlayer
camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = part
if player.Character then
local name = player.Character.Name
part = workspace[name].CameraPart
local cameraPosition = part.Position
end
local function OnChanged()
camera.Position = part.Position
wait()
end
Run.RenderStepped:Connect(OnChanged)
Other than the fact that the whole thing’s a hot mess, what am I doing wrong?
Do you think it’s because the part is currently under StarterPlayer? The model copies over from there to replace the standard player model, is there a way I could bind the camera to the local player? I’ve tried part=player.CameraPart but that’s an invalid member of the local player. From the debug I can see that it’s looking under Players.ManateeDerp47 (me) instead of Workspace.ManateeDerp47, I have a few ideas I want to try though so stand by
local char = player.Character or player.CharacterAdded:Wait()
if char then
local name = player.Character.Name
part = workspace[name].CameraPart
local cameraPosition = part.Position
end
--// rest of code
If I keep it in StarterPlayerScripts it’s saying I attempted to index nil with CFrame
If I put it in StarterCharacterScripts it works (yay) but it’s also giving me infinite yields. I’m not too concerned about them, since it still works, but I’m not sure what they mean
I got an output error that HumanoidRootPart isn’t a valid member of Workspace.ManateeDerp47. I fixed most of the infinite yields by moving the control script into StarterCharacterScripts next to the camera script, all that remains is a small alert that ActivateCameraController did not select a module.
As for the “why” of it, that was just the simplest (but not at all efficient) way I could think of to accomplish the end goal
If the part being manipulated is not in workspace, it doesn’t see it as moving since its not a visible object if that makes any sense (this isn’t a technical explanation, it’s just to make sense).
Make sure the part your editing is in workspace. if needed; put a fake part in replicatedstorage and clone it to workspace each time a user enters a spaceship and when they jump out of the spaceship it deletes the part.
The spaceship is the player, there is no entering and exiting the ship. The part eventually ends up in workspace, it get cloned from StarterPlayer.
The (probably inefficient) solution ended up being as simple as moving the script from StarterPlayerScripts to StarterCharacterScripts, so all I have to do now is hash out the movement.