The error message “attempt to index nil with ‘CFrame’” means that the variable campart in your ChangeCam RemoteEvent handler function is nil, and therefore does not have a CFrame property to index.
In your MakePoop RemoteEvent handler function, you are passing the playersPoop.CamPart as an argument to the ChangeCam RemoteEvent. However, it seems like the playersPoop object does not have a CamPart child, which is causing the campart variable to be nil.
To fix this error, you need to make sure that the playersPoop object has a child called CamPart that you can use as the argument for the ChangeCam RemoteEvent. You can do this by adding a part to the playersPoop model and renaming it to “CamPart”, or by adding a new part to the model with the name “CamPart”.
Once you have added the CamPart child to the playersPoop object, you should be able to use it as the argument for the ChangeCam RemoteEvent, and the camera should follow the part as expected.
local UIS = game:GetService("UserInputService")
local MakePoop = game:GetService("ReplicatedStorage"):WaitForChild("MakePoop")
local ChangeCam = game:GetService("ReplicatedStorage"):WaitForChild("ChangeCam")
local cam = workspace.Camera
local camera1 = workspace.camera1
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Space then
print("pooped")
MakePoop:FireServer()
end
end)
ChangeCam.OnClientEvent:Connect(function(player, campart)
print("tracking "..player.Name)
cam.CFrame = campart.CFrame
end)
Script (Script inside ServerScriptService)
local MakePoop = game:GetService("ReplicatedStorage"):WaitForChild("MakePoop")
local ChangeCam = game:GetService("ReplicatedStorage"):WaitForChild("ChangeCam")
local Poop = game:GetService("ReplicatedStorage"):WaitForChild("Poop")
MakePoop.OnServerEvent:Connect(function(player)
local playersPoop = Poop:Clone()
playersPoop.Name = tostring(player.Name).."_Poop"
playersPoop.Parent = game.Workspace
ChangeCam:FireClient(player, playersPoop.CamPart)
end)
Camera (LocalScript inside StaterGui)
local StarterGui = game:GetService("StarterGui")
local tween = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")
local cam = workspace.Camera
local camera1 = workspace.camera1
UIS.ModalEnabled = true
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
repeat wait() until cam.CameraSubject ~= nil
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = camera1.CFrame
It’s happening at line 18 in the UIS script so I assume it’s the onclientevent chunk
add a debug print (or use the debugger) to see which variable is causing the error
local UIS = game:GetService("UserInputService")
local MakePoop = game:GetService("ReplicatedStorage"):WaitForChild("MakePoop")
local ChangeCam = game:GetService("ReplicatedStorage"):WaitForChild("ChangeCam")
local cam = workspace.Camera
local camera1 = workspace.camera1
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Space then
print("pooped")
MakePoop:FireServer()
end
end)
ChangeCam.OnClientEvent:Connect(function(player, campart)
print("tracking "..player.Name)
warn(`DEBUG: Camera is {cam} and CamPart is {campart}`)
workspace.CurrentCamera.CFrame = campart.CFrame
end)
Take a screenshot of the debug warn here and it’ll show which variable is erroring
Edit: found the issue, remove player from the onclientevent
ChangeCam.OnClientEvent:Connect(function(campart)
warn(`DEBUG: Camera is {cam} and CamPart is {campart}`)
workspace.CurrentCamera.CFrame = campart.CFrame
end)
If you want the player variable to stay, you’re missing a part of the FireClient
local MakePoop = game:GetService("ReplicatedStorage"):WaitForChild("MakePoop")
local ChangeCam = game:GetService("ReplicatedStorage"):WaitForChild("ChangeCam")
local Poop = game:GetService("ReplicatedStorage"):WaitForChild("Poop")
MakePoop.OnServerEvent:Connect(function(player)
local playersPoop = Poop:Clone()
playersPoop.Name = tostring(player.Name).."_Poop"
playersPoop.Parent = game.Workspace
ChangeCam:FireClient(player, player, playersPoop.CamPart)
end)
One last thing though, how would I make it repeatedly follow the part, because its a moving part.
Right now it just shows where it was when the space bar was clicked.
Would I just use a while wait(0.1) do or a repeat?