Why does this script not work?

the script:

plr.CharacterAdded:Connect(function(char)
		wait(3)
		
			local camera = workspace.currentcamera
			camera.CameraType = Enum.CameraType.Scriptable
			camera.Parent = char
			camera.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(0, 10, 0)
			camera:GetPropertyChangedSignal("CFrame"):Connect(function()
				camera.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(0, 10, 0)
			end)

im thinking its because it is as server script, any ideas? thanks

2 Likes

This isn’t the full script - could you show us the full one? There are also some immediate issues I can spot:

  1. It’s workspace.CurrentCamera, not workspace.currentcamera
  2. Don’t set the camera’s parent. I believe you want the CameraSubject property: Camera | Documentation - Roblox Creator Hub

What are you even trying to do, btw? This would be better off as a local script but a server script should still work.

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		wait(3)
		
			local camera = workspace.currentcamera
			camera.CameraType = Enum.CameraType.Scriptable
			camera.Parent = char
			camera.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(0, 10, 0)
			camera:GetPropertyChangedSignal("CFrame"):Connect(function()
				camera.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(0, 10, 0)
			end)
		
		char.Animate.idle.Animation1.AnimationId = "rbxassetid://14057633432"
		char.Animate.walk.WalkAnim.AnimationId = "rbxassetid://14057633432"
		char.Animate.run.RunAnim.AnimationId = "rbxassetid://14057633432"
	end)
end)
local Ball = game.ReplicatedStorage.Accessory
workspace:WaitForChild("foxnoobkite").Humanoid:AddAccessory(Ball:Clone())

i am just trying to attach the camera above the player so it would be locked onto it

Can you tell me what errors are in the output?

rs:BindToRenderStep("LockCamera", 201, function(dt)
	cam.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(0, 10, 0)
	cam.CFrame = CFrame.lookAt(cam.CFrame.Position, hrp.Position)
end)

Try this, this’ll have the camera above the player and have it facing down onto the player.

i assumed you meant remote settings, so i did this,

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		wait(3)
		local rs = game:GetService("RenderSettings")
			local camera = workspace.currentcamera
			
		rs:BindToRenderStep("LockCamera", 201, function(dt)
			camera.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(0, 10, 0)
			camera.CFrame = CFrame.lookAt(camera.CFrame.Position, char.HumanRootPart.Position)
		end)
		char.Animate.idle.Animation1.AnimationId = "rbxassetid://14057633432"
		char.Animate.walk.WalkAnim.AnimationId = "rbxassetid://14057633432"
		char.Animate.run.RunAnim.AnimationId = "rbxassetid://14057633432"
	end)
end)
local Ball = game.ReplicatedStorage.Accessory
workspace:WaitForChild("foxnoobkite").Humanoid:AddAccessory(Ball:Clone())

can’t change camera on server scripts. current camera doesn’t point out to anything as the server doesn’t really have one. try sending a remote event to a player when he spawns to change his camera (in a local script this time). Also, RenderStepped does not work in server scripts and by “rs” he meant RunService, and not uh… remote settings.

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		wait(3)
		local rs = game:GetService("RunService")
			local camera = workspace.CurrentCamera
			
		rs:BindToRenderStep("LockCamera", 201, function(dt)
			camera.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(0, 10, 0)
			camera.CFrame = CFrame.lookAt(camera.CFrame.Position, char.HumanRootPart.Position)
		end)
		char.Animate.idle.Animation1.AnimationId = "rbxassetid://14057633432"
		char.Animate.walk.WalkAnim.AnimationId = "rbxassetid://14057633432"
		char.Animate.run.RunAnim.AnimationId = "rbxassetid://14057633432"
	end)
end)
local Ball = game.ReplicatedStorage.Accessory
workspace:WaitForChild("foxnoobkite").Humanoid:AddAccessory(Ball:Clone())




yeah nothing happpened, atleast no errors popped up

and this is a local script ? it seems you’re still using a server script

local rs = game:GetService("RunService")
local camera = workspace.CurrentCamera

rs:BindToRenderStep("LockCamera", 201, function(dt)

	local char = game.Players.LocalPlayer.Character

	camera.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(0, 10, 0)
	camera.CFrame = CFrame.lookAt(camera.CFrame.Position, char.HumanRootPart.Position)
end)

changed script

it works but i keep getting this error

do you not understand what that means ? or is that script not yours ? eitherway ;

local rs = game:GetService("RunService")
local camera = workspace.CurrentCamera

rs:BindToRenderStep("LockCamera", 201, function(dt)

	local char = game.Players.LocalPlayer.Character

	camera.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(0, 10, 0)
	camera.CFrame = CFrame.lookAt(camera.CFrame.Position, char.HumanoidRootPart.Position)
end)

-- this should fix it

shoot, you’re right, didn’t really look closely at the error.
is there a way i can lock the camera?

UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter

sorry i wasn’t being very detailed, i meant locking the rotation too, right now it is just one spot without rotating. i would like it to lock on also the rotation and position

sorry, can you explain a little more?

right now, it is following the humanrootpart with an added position, i would like it to also rotate with the player so that the humanrootpart looks like it always is the same angle


in short, camera facing where humanrootpart is facing

Camera.CFrame = CFrame.new((character.HumanoidRootPart.CFrame * CFrame.new(0, 0, 0)).Position, character.HumanoidRootPart.Position)

play around with this a bit (by changing the CFrame.new coordinates), this make it so that the camera follows the rotation of the humanoid root part as well as his position

also no not like shiftlock, i am trying to make the humanrootpart to control the camera, not the other way around

lol when i walk it spins me, and when i shiftlock it goes very fast

obviously, shiftlock is not intended to work if you’re working with custom cameras. did you modify my script or did you just use it as given ?