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

Camera not Attaching to Part?

Asked by 4 years ago

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.

0
try replacing line 5 with this: TheRealPotatoChips 793 — 4y
0
camera.CFrame = CFrame.new(workspace.Camera1.Position) TheRealPotatoChips 793 — 4y
0
Thanks for your comment! Seem it hasn't worked, thanks anyway! OkxieCorey 125 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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!

0
Hello Vince! Thank you for the answer, however this doesn't seem to work, doesn't show any errors either. OkxieCorey 125 — 4y
0
Is the server script inside of a brick? Vinceberget 1420 — 4y
Ad

Answer this question