Hi,
So I am wondering, which of the following should I use for an Opening / Closing script.
The following script is just to Hide the players UserId for a profile I’m making, I already know how to script it, but I’m just asking for support on which method I should use.
local Opened = false
script.Parent.MouseButton1Down:Connect(function()
if Opened == false then
Opened = true
script.Parent.Parent.PlayerUserId.Spoiler.Visible = false
elseif Opened == true then
Opened = false
script.Parent.Parent.PlayerUserId.Spoiler.Visible = true
end
end)
I tested these out and they both seem to work the same. I’m just asking which one should I use.
Personally I like the second one. It’s just a bit more clear in my opinion.
Also you can actually shorten it a bit if you wanted.
script.Parent.MouseButton1Down:Connect(function()
script.Parent.Parent.PlayerUserId.Spoiler.Visible = not script.Parent.Parent.PlayerUserId.Spoiler.Visible
end)
Though it might be a bit easier to read this way
local Opened = false
script.Parent.MouseButton1Down:Connect(function()
Opened = not Opened
script.Parent.Parent.PlayerUserId.Spoiler.Visible = Opened
end)
Well, I should also note that I only think the second one in the case you intend to use the same button. If you want different styles and locations to the button then I’d prefer the first. Though I’d keep it in the same script so all the similar functionality is in the same place if possible.
local Spoiler = script.Parent.Parent.PlayerUserId.Spoiler
script.Parent.Activated:Connect(function(UserInput, ClickCount)
-- This only allows Left click and touch to activate the button.
if (UserInput.UserInputType ~= Enum.UserInputType.MouseButton1)
and (UserInput.UserInputType ~= Enum.UserInputType.Touch) then return end
Spoiler.Visible = not Spoiler.Visible
end)