Random things I've learned

Out of my three years of developing, there is lot’s of things I have learned. I’m going to share a lot with you today.

1: WorldRoot:Raycast() is faster than WorldRoot:GetPartsInPart()

2: If you want to know when a button is pressed and let go, then use GuObject.GuiState

3: Do most of your input on the client, and DON’T USE GuiButton.MouseButton1Click. Use .Activated on a client script instead. MouseButton1Click only works on computers.

4: If you can use a ModuleScript to encapsulate it, then encapsulate it.

5: Use variables and simplify your code.

6: Disconnect your useless connections to save memory.

7: Try to do all code related with UI on the client.

8: Try to make your UI usable for mobile too. Try using things such as UIAspectRatioConstraint.

9: Do you need some assets? Try Krita (for artwork) and Blender (for 3D models). Most of you probably already know this

10: Want to get a random item from a table? Do

local randomitem = yourtable[math.random(1, #yourtable)]

11: Want to get the up look vector? Here’s how:

local upvector = yourCframe.UpVector

12: TweenService is not like a terribly hard service that will kill your time. DON’T YOU DARE DO IT MANUALLY!! Here’s how to use it:

local TweenService = game:GetService("TweenService")

local part = Instance.new("Part")

local params = TweenInfo.new(3, Enum.EasingStyle.Linear)

local properties = {
    Transparency = 1
}

local newtween = TweenService:Create(part, params, properties)

newtween:Play()

This code will make a part go from fully opaque to fully transparent in three second. Here’s some info on TweenInfo and the ‘newtween’.

13: Use Selection when you’re developing. Open the command bar and then select an object and type in the command bar something like

print(game:GetService("Selection"):Get()[1].CFrame) 

and then look at the output.

List will continue…

Feel free to add anything!! Anything you’ve learned that might be helpful for others?

22 Likes

These are nice and all, but explanations would be nicer.


local upVector = yourCFrame.UpVector
1 Like

Yah, I just realized that. My bad.

1 Like

beginners pet peeves ever,.,.,.,…,.,.

2 Likes

about #10… it will tgenerate duplicated values from a table perchance, if you use it multiple times.

so recently i wrote the post that suggests a bit complicated approach.

some guy also suggested another way to go through the table, that one also seem useful.

i’m just sharing in the end, good luck with future experience/projects!

I utilize #6 so much now, i decided to make the connections table for my plugin a global variable (don’t worry, i named it uniquely) so whenever i reload said plugin, it cleans up every connection, it’s kinda become instinct now lol

1 Like

I don’t understand this, aren’t they used for completely different purposes?

2 Likes

I had a recent creation that I could use either, one would’ve been easier, and one would have been faster. Just some random thoughts. Sorry for the misunderstanding.

i think it’s easier and cheaper to cast one ray rather than calculating every colliding part, the advice has logic really

A lot of people make the mistake of using a while loop and then using :GetChildren() or :GetDescendants() in order to update a table. Instead it’s best to use .DescendantAdded and .ChildAdded, this is a issue that a lot of people struggle from.

1 Like

Been a while, but hex colors (#f56ed4) are pretty easy to read. Here’s how.

1: Split it

Split the hex into 3 parts for red green and blue

R: f5
G: 6e
B: d4

2: Convert it to decimal

Convert the hexadecimal to decimal by multiplying the first digit by 16 and adding.

Remember, a is 10, b is 11, c is 12, d is 13, e is 14, and f is 15

R: f = 15,
15 * 16 = 240,
240 + 5 = 245,
R = 245

G: 6 * 16 = 96,
e = 14,
96 + 14 = 110,
G = 110

B: d = 13,
13 * 16 = 208,
208 + 4 = 212,
B = 212

#f56ed4 = 245, 110, 212

You have just converted your first hex!

4 Likes

3: Do most of your input on the client, and DON’T USE GuiButton.MouseButton1Click . Use .Activated on a client script instead. MouseButton1Click only works on computers.

This is absolutely not true. I have a whole game where literally all the buttons use MouseButton1Click and everything works fine on the phone and other devices. It’s just that Activated allows you to track the input device you’re playing on. So that function work not “only for computers”.

Have you tried it on other devices BESIDES the device simulator?

Yes, my game is published and I played it.

It is one of my first games, it does not look very good, but it works and I tested it many times including on my phone.

You can create a simple game with a small number of GUI buttons, publish it and you will see that everything works from different devices even if you use MouseButton1Click. Although the documentation says that the button only works for a mouse - this is not true.

Before answering you, I checked that my game uses MouseButton1Click, then I went to read on the forum whether there is a difference between Activated and MouseButton1Click, moreover, there is a comparison on the forum here, where it is written that they work in a similar way, but supposedly have a higher priority for devices and it seems that it is better to use Activated, but there is no evidence, it just says that it is probably better this way and that’s it, there are no messages saying that it stopped working for me because of MouseButton1Click.

My post is not meant to prove that MouseButton1Click is better than Activated, I’m more saying that you said that it generally doesn’t work on other devices, but it does. Activated is better because it return input device. But they work in a similar way.