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

My First Person Script Works, but it also doesn't work at the same time?

So basically I wanted to make a first person script, and I wanted the first person script to be non-active when the gui is showing. So it works for that, but when its time to make it first person its still not active. I've tried to fix it the lazy way, but still didn't work.

game.StarterPlayer.CameraMaxZoomDistance = 0 else if
	game.StarterGui.ScreenGui.Frame.Visible = true then
	game.StarterPlayer.CameraMaxZoomDistance = 2 else if
		game.StarterGui.ScreenGui.Frame.Visible = false then
		game.StarterPlayer.CameraMaxZoomDistance = 0
	end
end
game.StarterPlayer.CameraMinZoomDistance = 0 else if
	game.StarterGui.ScreenGui.Frame.Visible = true then
	game.StarterPlayer.CameraMinZoomDistance = 2 else if
		game.StarterGui.ScreenGui.Frame.Visible = false then
		game.StarterPlayer.CameraMinZoomDistance = 0
	end
end

wait(.1) then
game.StarterPlayer.CameraMinZoomDistance = 0
game.StarterPlayer.CameraMaxZoomDistance = 0

So that's the script, can anybody tell me whats wrong with it...

1 answer

✓ Accepted answer

Whats with the whole else if true then thing?

I don't think you understand the usage of if _ then statements yet, or programming in general. I highly recommend reading up some basic tutorials such as this intro to scripting playlist from ROBLOX.

  1. First of all, if you want to check if a value is 0, then you use two equal signs.
  2. Please use variables so you don't have to write out game.StarterPlayer.. and gmae.StarterGui.ScreenGui...
  3. Editing StarterGui does not change the player's gui, you need to go to PlayerGui
  4. Editing StarterPlayer does not change the player's camera, you need to edit the player directly.
  5. Instead of editing max/min zoom distance, why don't you just lock the player to first person using Player.CameraMode
  6. Don't put then after everything. It only is put after an if statement
  7. The if statement works like this:
if CONDITION then
	-- code goes here
elseif OTHER CONDITION then
	-- other code goes here
else
	-- if none of the above conditions
end

-- or if you want simply an if statement
if CONDITION then
	-- code here
end

I really hope this information helps! :)

3 comments

0

yea im pretty new to scripting, so I kinda thought I knew what I was doing then I didn't work. So I get it now, thx

0

On line 3, you spaced elseif. This will cause Lua to interpret it as a new line, thus needing another end

0

fixed. thanks incap

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