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

LockFirstPerson - How do i correctly do it?

Asked by 10 years ago

I have this script, that's inside of a button.

function onClicked()
script.Parent.Parent.Parent:remove()
print("everything removed")
game.Players.LocalPlayer.CameraMode = "LockFirstPerson"
print("FirstPersonisLocked")
end

script.Parent.MouseButton1Click:connect(onClicked)

When i test it out in Play Solo, it works fine. But in a server, it doesn't go to first person. It just closes out the Gui. (The first part of the script.)

Why does it do this? Can someone tell me a correct way to do it?

1 answer

Log in to vote
2
Answered by 10 years ago
script.Parent.MouseButton1Click:connect(function() -- Improved with anonymous function
    game:GetService("Players").LocalPlayer.CameraMode = "LockFirstPerson"
    script.Parent.Parent.Parent:Destroy()
    print("First person is now locked.")
end)

I have tested the above in-game and it worked fine for me. I think it was due to the fact that you were removing the GUI before adjusting the CameraMode.

Ad

Answer this question