So basically i’ve made another camera manipulation script. You just walk on a part and your camera is on the position of a part. Here is what i’ve made :
local hit = script.Parent.Touched:Wait()
local camera = game.Workspace.CurrentCamera
function UpdateCamera()
camera.CFrame = game.Workspace.Part1.CFrame
end
I don’t really get why it doesn’t work. Does anyone know?
You should set its CameraType to scriptable first for it to allow changing its position. Also, I’d recommend using :Connect() instead of :Wait(), because variables can be defined first and the action can be performed and disconnected at any time.
Apart from that, LocalScripts don’t run inside workspace, if you’re using a server-sided script changing the camera’s CFrame will affect the server’s current camera, not the player’s one, so the best thing to do I can think of is just to use a RemoteEvent from server to client.
local hit = script.Parent
local camera = game.Workspace.CurrentCamera
local function UpdateCamera(hit)
local Character = hit:FindFirstAncestorWhichIsA("Model")
local Humanoid = Character and Character:FindFirstChild("Humanoid")
if Humanoid then
local Player = game.Players:GetPlayerFromCharacter(Character)
if Player then
-- fire remoteevent
end
end
end
hit.Touched:Connect(UpdateCamera)