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

How can I toggle StarterPlayer FPS on/off on roblox studio?

I have a script, I edited it from a free model.. I added in the codes after it shows "e" and I changed it from (Player = script.Parent.Parent) to (Players = Players.LocalPlayer) Is that right?. Can someone please help? I want it so when someone presses E they can either toggle from FPS mode to classic and press again to change from classic to FPS. And I left the original author there to show I didn't EXACTLY create it..

Players = Players.LocalPlayer
mouse = Players:GetMouse()

function onKeyDown(key)
key = key:lower()
if Players.LocalPlayer.Open.Value == false then
	if key == "e" then --start
		game.StarterPlayer.CameraMode.LockFirstPerson = false
		game.StarterPlayer.CameraMode.Classic = true
	end
elseif Players.LocalPlayer.Open.Value == true then
	if key == "e" then  --E is the key to open and close
		game.StarterPlayer.CameraMode.Classic = false
		game.StarterPlayer.CameraMode.LockFirstPerson = true
		end
	end 
end


mouse.KeyDown:connect(onKeyDown)

--IciFlame

1 answer

✓ Accepted answer

If you are doing a LocalPlayer you must make the script in a local script. Also, regarding the Player = Players.LocalPlayer. That should be

local Player = game.Players.LocalPlayer

The function should also be

function onKeyDown(key)
	key = key:lower()
	if Player.Open.Value == false then
		if key == "e" then --start
			game.StarterPlayer.CameraMode.LockFirstPerson = false
			wait()
			game.StarterPlayer.CameraMode.Classic = true
		end
	elseif Player.Open.Value == true then
		if key == "e" then  --E is the key to open and close
		        game.StarterPlayer.CameraMode.Classic = false
			wait()
			game.StarterPlayer.CameraMode.LockFirstPerson = true
		end
	end
end

Remember this HAS to be in a LocalScript.

1 comment

0

Did not work, and is in a LocalScript in starterpack.

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