Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why isn't the camera CFrame changing?

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)

5 comments

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
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:

0

The problem is that it already is on Scriptable. Sorry for not clarifying.

2

i dont see a problem with this question though? @JesseSong

0

^

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.