I’m hopefully trying to get as the title said, the camera to change once a player clicks it.
I’m not entirely sure how the camera system works so I could be doing something wrong.
Not sure if it’s a client side only, or if I can fire it on server side. My current script goes as follows
local part = game.Workspace.camcam
part.ClickDetector.MouseClick:Connect(function(mouse)
local player = mouse
local camera = game.Workspace.Camera
camera.CameraType = "Scriptable"
if player then
print("Player " .. player.Name .. " clicked the part.")
camera.CFrame = CFrame.new(game.Workspace.newcam.Position)
end
end)
Once I do this it doesn’t change the players camera. However I have seen and watched some tutorials before that have “enum” but I’m not sure where I would put that. I have a feeling that I am not actually setting the players camera to anything. If theres anything I can do to fix this, it would be greatly appreciated.
How would I do that? Since click detectors use server scripts, I’m not exactly sure how to get to the client side. Remote events don’t work as thats client to server
Remote events can handle server-to-client and client-to-server. Since your click detectors are used in a server script, you can use a remote event to fire to the player that clicked it and manipulate the camera from the local script that handles the remote events.
Alright good to know. I apologies for the questions, but how do I make the remote event client to server?
For my new script on the part you click it is
local click = script.Parent.ClickDetector
local part = script.Parent
part.ClickDetector.MouseClick:Connect(function(mouse)
local player = mouse
game.ReplicatedStorage.camera:FireClient(player)
end)
and on my script inside replicated storage it is
local rs = game:GetService("ReplicatedStorage")
local cam = rs:WaitForChild("camera")
local function changecamera()
print("fired, at least")
local part = game.Workspace.camcam
local camera = game.Workspace.Camera
camera.CameraType = "Scriptable"
camera.CFrame = CFrame.new(part.Position)
end
cam.OnServerEvent:Connect(changecamera)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("ChangeCamera")
script.Parent.MouseClick:Connect(function(Player) -- by default, the first parameter of MouseClick is the Player
RemoteEvent:FireClient(Player) -- SENDING SIGNAL TO PLAYER
end)
Client:
local Camera = workspace.CurrentCamera -- CAMERA
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- REPLICATED STORAGE
local RemoteEvent = ReplicatedStorage:WaitForChild("ChangeCamera") -- REMOTE EVENT
RemoteEvent.OnClientEvent:Connect(function() -- PLAYER RECEIVING THE SIGNAL
Camera.CameraType = Enum.CameraType.Scriptable -- CHANGING CAMERA TYPE
Camera.CFrame = workspace.newcam.CFrame -- CHAGING CAMERA CFRAME TO NEWCAM CFRAME
end)