So I am making a custom camera attached to an cloned part from replicated storage and I don't know how to place a players camera to this part. here is some code for the part.

local rp = game.ReplicatedStorage
local Cam = rp:WaitForChild('CustomCamera')

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		CCam = Cam:Clone()
		CCam.Parent = char
		local newCFrame = char:WaitForChild('Torso').CFrame
		
		CCam.CFrame = CFrame.new(Vector3.new(newCFrame.X,newCFrame.Y+2,newCFrame.Z-7))
		
		local Weld = Instance.new("ManualWeld")
		Weld.Part0 = CCam
		Weld.Part1 = char:WaitForChild('Torso')
		Weld.C0 = CCam.CFrame:inverse() * char:WaitForChild('Torso').CFrame
		Weld.Parent = char:WaitForChild('Torso')
	end)
end)

I have a part named "CustomCamera" in replicated storage. the script is a server-side script in server script service. I am using the "play" feature to see if any of the camera scripts I write will attach to the part. Involving my current camera script (as in, the time of writing). the output is telling me "CCam is not a valid member of Model". the current camera script I am using is a local script in "Starter Character"

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local cam = workspace.CurrentCamera

local rs = game:GetService('RunService')
local uis = game:GetService('UserInputService')

local cframe,vector3,eulerYXZ,rad,abs = CFrame.new,Vector3.new,CFrame.fromEulerAnglesYXZ,math.rad,math.abs
local partToFollow = char.CCam
local axis = vector3(0,0,0)
local zoom = 0


repeat wait() until game:IsLoaded()

uis.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton2 then
		uis.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
	end
end)

rs.RenderStepped:Connect(function()
	local delta = uis:GetMouseDelta()
	local partPosition = partToFollow.Position
	axis=axis+vector3(rad(delta.Y),rad(delta.X),0)
	cam.CFrame = cframe(partPosition)*eulerYXZ(axis.X,axis.Y,0)
end)

I am new to Scripting for roblox and got these from youtube tutorials. I need help with getting a camera script that attached to ccam

1 comment

0

Update: I looked at my scripts and updated them. even if i wait for the game to load before waiting to execute the script, it still thinks that the Custom Camera part doesnt exist