When the player touches the part it's supposed to change the camera CFrame. Although, nothing happens. This is the code i'm using. (LocalScript) Edit: The camera is already on "Scriptable"
local Camera = workspace.CurrentCamera script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then Camera.CFrame = workspace.CAMS.S1B.CFrame end end)
The problem is that your LocalScript is local, and since your part is created on the server, IE: In studio, the LocalScript simply wont work. This is problematic since the camera can only be changed locally, and we already know that we can't use a LocalScript to detect when the part collides with something.
The easiest way to bypass this would be by using a RemoteEvent
to send a message through the client-server boundary. In this example we'll be creating a RemoteEvent
object and placing it inside the ReplicatedStorage
, this storage basically replicates objects inside so that they exist in both server-space and local-space, which is perfect for what we want. For convenience, we'll name the RemoteEvent
object 'touchBrick'.
Since we want to send a message to the client we will use the FireClient()
function, which uses a Player
object as its first argument, this decides who the message will be sent to.
Then we can use the OnClientEvent
function to detect when the LocalScript receives a message.
Server Script
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- we get the player object from the character object game.ReplicatedStorage.touchBrick:FireClient(player) end end)
Local Script
game.ReplicatedStorage.touchBrick.OnClientEvent:Connect(function()) workspace.CurrentCamera.CFrame = workspace.CAMS.S1B.CFrame end)