Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why isn't the camera CFrame changing?

Asked by 3 years ago
Edited 3 years ago

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)
0
You need to set the camera type to Scriptable ~~~~~~~~~~~~~~~~~ -- to edit camera Camera.CameraType = Enum.CameraType.Scriptable -- default camera Camera.CameraType = Enum.CameraType.Custom ~~~~~~~~~~~~~~~~~ CaioAlpaca 342 — 3y
0
@BoomerNEW_GEN please use the developer hub/devforum for reference in the future, otherwise your question may be closed as "Not Constructive!" if you'd like to learn how to post a good question, then here' the link: https://scriptinghelpers.org/help/how-post-good-questions-answers: JesseSong 3916 — 3y
0
The problem is that it already is on Scriptable. Sorry for not clarifying. User#37681 0 — 3y
2
i dont see a problem with this question though? @JesseSong zadobyte 692 — 3y
0
^ CaioAlpaca 342 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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)
Ad

Answer this question