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

LockFirstPerson - How do i correctly do it?

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

✓ Accepted answer
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.

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