I am wanting to know how to script better. I also want to be able to make scripts so if another scripter comes to change the script they know where and how to do it. Is there anything I need to change or add to the script?
-- LOCAL SCRIPT LOCATED IN MAINUI [UPDATED 12/09/2023]
-- <<VARIABLES>>
-- BUTTONS
local statsButton = script.Parent.Buttons.StatsButton
local statFrameClose = script.Parent.StatFrame.CloseTextButton
-- GUI
local statFrame = script.Parent.StatFrame
-- <<FUNCTIONS>>
-- FUNCTION TO CHANGE STATFRAME VISIBILITY
local function onStatsButton()
statFrame.Visible = not statFrame.Visible
end
-- <<CONNECTIONS>>
statsButton.MouseButton1Click:Connect(onStatsButton)
statFrameClose.MouseButton1Click:Connect(onStatsButton)
this looks great! the script IS very simple though, so i want to add that adding some comments to different sections of some especially large function can be helpful
speaking of functions, there is a standard format for documenting them.
-- Returns the inputted number * 2
-- @param num: the inputted number
-- @return: the number * 2
local function timesTwo(num)
return num * 2
end
obviously this is a very simple example. hope this helps!
The script is very simple; it doesn’t need anything. In fact I would probably personally remove some of the comments. For example, instead of using a comment here
-- FUNCTION TO CHANGE STATFRAME VISIBILITY
local function onStatsButton()
statFrame.Visible = not statFrame.Visible
end
you could use a more descriptive function name
local function changeStatFrameVisibility()
statFrame.Visible = not statFrame.Visible
end
Though, it doesn’t really matter.
You can also follow Roblox Lua Style guide if you’d like.
EDIT: I also agree with the above reply, document your code if you want others to use it.