[Scripting] Things I wish I knew about earlier

I am not quite sure if this is the right category to put it in.

This is my first post.

This list will be about functions or other things I wish I knew earlier: For example task.wait
I will make sections with the title of the function you might want to replace or add something too.

wait(duration)

Type: Replace

Code: task.wait(duration)

Reason: Wait returns more unnecessary things, that’s why task.wait() is more accurate and better for performance.

local Service = game.Service

Type: Replace

Code: local Service = game:GetService("Service")

Reason: game:GetService() also works when the services are renamed and it waits for them to load.

DataStore:SetAsnyc(key, value)

Type: Replace

Code: Use UpdateAsnyc, implementation depends on your DataStores, consider checking out this tutorial.

Reason: Someone already explained it really well, consider checking out this reply.

game:GetService("Players").PlayersAdded:Connect

Type: Add

Code: `for _, player in game:GetService(“Players”) do
— Do the same thing as player added.
end

Reason: Players might join before the PlayerAdded gets connected.

game:GetService("Players").PlayerRemoving:Connect

Type: Add

Code: game:BindToClose(function() for _, player in game:GetService(“Players”) do
— Do the same as PlayerRemoving if it isn’t like showing something to the other users, as the server is closing.
end
end)

Reason: When roblox closes a server for maybe maintenance the Players don’t leave until it is down and that means PlayerRemoving doesn’t fire, but with game:BindToClose() we can run code 30 seconds before shutdown.

Feel free to share some of the things you wished you knew earlier about.

2 Likes

Added DataStore:SetAsnyc(key, value).