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.
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!