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

Camera not Attaching to Part?

Hello! I have tried countless times for this:

I want to change your camera to lock onto a part when you touch a block, this is the LocalScript I created:

script.Parent.Touched:connect(function(h)
	if h.Parent:FindFirstChild("Humanoid") then
		local camera = workspace.CurrentCamera
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CFrame = workspace.Camera1.CFrame
	end
end)

All help appreciated! Thank you.

3 comments

0

try replacing line 5 with this:

0

camera.CFrame = CFrame.new(workspace.Camera1.Position)

0

Thanks for your comment! Seem it hasn't worked, thanks anyway!

1 answer

Unfortunately it seems that the Touched event wont fire on clients, but the server. You can bypass this by using RemoteEvents.

In LocalScript:

game.ReplicatedStorage.REMOTEEVENT.OnClientEvent:Connect(function()
	local camera = workspace.CurrentCamera
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = workspace.Camera1.CFrame
end)

In Server script:

script.Parent.Touched:connect(function(h)
	if h.Parent:FindFirstChild("Humanoid") then
game.ReplicatedStorage.REMOTEEVENT:FireClient(game.Players:FindFirstChild(h.Parent.Name))
	end
end)

You can replace REMOTEEVENT with whatever you want the RemoteEvent to be called, just make sure there is a RemoteEvent in ReplicatedStorage with the same name.

Hope this helps!

2 comments

0

Hello Vince! Thank you for the answer, however this doesn't seem to work, doesn't show any errors either.

0

Is the server script inside of a brick?

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