My intention is to make the camera’s CFrame when the player is touching a brick. I’ve used this local script below:
local player = game.Players.LocalPlayer
local db = false
local cam = workspace.CurrentCamera
local campart = workspace.Cam
script.Parent.Touched:Connect(function(hit)
if not db then
db = true
if hit.Parent:FindFirstChild("Humanoid") then
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = campart.CFrame
end
end
end)
but it doesn’t work. There’s no output or any errors whatsoever.
The only way I know how to change the camera’s CFrame is by placing a script in the brick that activates a local script in StarterGui. However, that seems quite troublesome rather than having just 1 script in my opinion.
Yeah, you would need to access the client’s CurrentCamera by a LocalScript and handle the onTouch event on the server.
LocalScript; place in StarterCharacterScripts or StarterPack
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local SetCameraType = ReplicatedStorage:WaitForChild("SetCameraType");
local CurrentCamera = workspace.CurrentCamera;
local changedCamera = false;
if not changedCamera then
SetCameraType.OnClientEvent:Connect(function(cameraPart)
CurrentCamera.CameraType = Enum.CameraType.Scriptable;
CurrentCamera.CFrame = cameraPart.CFrame;
end)
end
ServerScript; Placed within the touched part.
local Players = game:GetService("Players");
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local part = script.Parent;
local cameraPart = workspace:FindFirstChild("CameraPart");
local setCameraType = Instance.new("RemoteEvent");
setCameraType.Name = "SetCameraType";
setCameraType.Parent = ReplicatedStorage;
part.Touched:Connect(function(hit)
local Character = hit.Parent;
local Humanoid = Character:FindFirstChild("Humanoid");
if Humanoid then
local Player = Players:GetPlayerFromCharacter(Character);
setCameraType:FireClient(Player, cameraPart);
end
end)