Script editor incorrectly auto-indents some if statements


#1

While editing scripts in Roblox Studio’s Script editor: pressing enter on the line of an END statement can incorrectly auto-indent that line, and the line that follows it.

See what happens when I try to create a new line by hitting enter at line 29:

Image from Gyazo

Here is the exact code. This bug is reproduced 100% by the IF statement on line 29, as shown in the gif above. Just copy/paste this code into script editor and try to start a new line after the END statement that closes module.partyRequest

local module = {}

local activePlayer


function module.init(Modules)
	local tween = Modules.tween
	local network = Modules.network
	
	function module.open(player)
		activePlayer = player

		script.Parent.UIScale.Scale = 0.75
		Modules.tween(script.Parent.UIScale, {"Scale"}, 1, 0.5, Enum.EasingStyle.Bounce)	
		Modules.focus.toggle(script.Parent)
	end	

	function module.partyRequest()
		if activePlayer and script.Parent.options.Visible then
			local target = activePlayer
			local success, reason 
				success, reason = network:invokeServer("playerRequest_invitePlayerToMyParty", target)
			if success then
				Modules.notifications.alert({text = "Invited "..target.Name.." to the party."}, 2)
			elseif reason then
				Modules.notifications.alert({text = reason or "Error occured"}, 2)
			end	
		end	
	end

		
end

	

return module



This issue happens 100% of the time. It has been happening for over half a year and it is seriously driving me insane.


[100%] Scope declaration words are opening new tabs in Script Editor, regardless of placement
Script Editor: Folding does not work properly when keywords in comments or elseif is involved
#2

This has been driving me insane lately. +1


#3

Is this the same issue?

The example in the first post has it on end) but example gifs later in the thread show it also happening to plain ends.


#4

Not exactly the same issue. In the linked post, it auto-indents the end statement but then the next line starts with the correct indentation.

With the above code, it auto-indents and starts the next line on the wrong indentation.


#5

I swear to god this bug actually drives me insane – I always have to go back and correct it. Please for the love of god get this fixed. :pray:


#6

This happens to me as well.


#7

This is quite an annoying bug, as someone who really wants their code to look clean and readable I have to spend extra effort reorganizing code when the indentation messes up. It interrupts workflow quite a bit.


#8

This happens to me quite often as well.


#9

Yeah, I can reproduce this and I like to keep my code clean and nice just in case I add someone to help me and don’t confuse them.


#10

Happens for me as well. But I get the “opposite” issue where ends indent to the left after closing a table and pressing enter. Here’s a sniplet of the code in question.

The issue happens at the very end, so if you try placing this into a function or just a “do end” statement, you should be able to replicate this easily.

local ud = newproxy(true) local mt = getmetatable(ud)
do
    local f={}
    local ntf = {}
	mt.__index={
		Fire=function(...)
			for i=1,#f do
				if f[i] then f[i](...) end
			end
		end,
		Connect=function(n,func)
			local i=1
			while f[i]do
				i=i+1
			end
			f[i],ntf[n]=func,i
		end,
		Disconnect=function(n)
			f[ntf[n]]=nil ntf[n]=nil
		end
	}
end

#11

I encountered something similar earlier with this incredibly simple function and it made me start looking into it further to see if I could get an actual detailed repro of this. I have, and the results of this are below along with a hypothesis on why this is happening.

Let’s start with my issue.
image
I have this code, and I wanted to collapse it. So, I clicked the arrow next to the function, and…
image
That’s not how folded functions are supposed to look. Upon further inspect, this was because the do-block from the for-loop wasn’t folding properly. So, I set about doing science (read: deleting one line then the other) to see which line was causing it, and it turned out to be Table[Table[i]] = true. Notably, ]] would normally indicate a folding endpoint for longstrings/comments, so I tried putting a space between the two brackets and it folded just fine:
image

This felt related to this bug so I decided to check and turns out, yes, they’re either almost the same or identical.

That actually solves the issue that @nooneisback was having as they have a ]] that’s throwing things out of wack. As it turns out though, it actually resolves the one that @berezaa was having in the OP and that @Usering reported a while back.

Turns out that this is actually a really simple problem: Anything that increases the tab/folding level increases the level by one, and anything that decreases it decreases it by one. As a result, elseif/else blocks and double table indexes, and possibly more are causing this problem.

Examples below

https://gyazo.com/8d5d54c543412a79540e9e599cfd89b0
https://gyazo.com/2d255a101c9b94a6925fd58cb9fb13e8
https://gyazo.com/f416e02ea572f2b44de514357d6eaaeb

Until this is fixed, there are some gross workarounds (like the -- ]] in the last gif) but I wouldn’t recommend them as permanent solutions because, well, ew.


#12

Hello Everyone,
With the most recent Studio release we have fixed a large amount of these issues regarding improper indentation. The bug with "]]"mentioned in Dekkonot 's post above this one still needs to be resolved, but you should no longer have issues with pressing enter after end statements resulting in improper indentation when elseif/else statements are involved.
In addition, we have resolved an issue regarding improper tab folding involving elseif/else statements, so those should work correctly now as well.
Thank you for your patience in resolving this issue. If other bugs are found, please do not hesitate to let us know.


[100%] Scope declaration words are opening new tabs in Script Editor, regardless of placement
#13

Yay, I can finally reopen studio and get back to work without pulling hair out! Thank you soo much! :slightly_smiling_face: