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