hehe no worries i meant no offence
my words don’t contain any sarcasm
sorry it confused you
i am not sad no worries
The things that helped me were continue
.
_G
is especially for global functions, where you can access things from other scripts if you set them.
and
& or
can be used like this:
animator = script.Parent:FindFirstChild("Humanoid") or script.Parent:FindFirstChild("AnimationController")
and & or can also be used to make a type of if statements
local randomBool = math.random(1, 2)==1 and true or false
Fun fact there is also the global table “shared” that even less people know of. Also I reccomend you fix some spelling errors. Also don’t use for I,v in next, table, don’t do that.
i didnt know that mind if i can use it in my tutorial and sorry for my spelling
Great tutorial but I have some critiques:
- Your code uses properties that don’t exist, such as
Player.team
, where it should bePlayer.Team
. - You don’t really explain how
next
operates and what’s happening in the code sample. - You’re not using proper English that people can understand. (You’re using slang like “peps”).
- In the “to long” section, for your second code example, you didn’t explain why what you did was better other than it was “short.”
- Mainly, there’s a lack of explanations.
Majority of my critiques are just nitpicks so don’t take them personally.
This is not true. The table does not replicate from client-server, but can be used on client.
guess my resources are wrong woops gonna fix that
Please use commas and grammar, it is extremely difficult to read this.
wow thank you, never knew shared existed
i tried my best to fix it but i am no grammar dude its my least favorite subject
me either i didn’t know till today but please… use modules
it was actually was the original tittle for number
Aahhh this is soo cool tysm, i want more things like that
i might make a part two lol when i learn more uncommon stuff
I wonder why does shared
exist, if _G
already did…
But hey, here’s more coding things that you probably didn’t know about, with good grammar as well!
sorry that my grammar sucks its not my best subject
next
Please don’t write loops this way, it’s unreadable. I know that pairs implements next (unless it doesn’t in Luau) but you should just use one of the proper generators when iterating; ipairs for contiguous arrays where ordering might be important and pairs for dictionaries.
Fake ternary (and & or)
Same as the above: be careful when you’re using this. There are some cases where developers may get “unexpected results” but that’s just a case of using this wrong. Luau doesn’t have a ternary operator so this is the closest that can be done without being actual ternary, this is just taking advantage of the way operators evaluate.
shared (or _G)
Good call: please never use either of these, opt for ModuleScripts. There are very exceptional cases where you need to use the global table otherwise try not to use it.
Dictionaries (“too long…”)
Each of these code samples has a minor problem.
-
Please use PascalCase when referring to properties. Team and Name should have a capital T and N respectively. The lowercase variants are deprecated aliases.
-
The second sample doesn’t work the way you think it does. You’ve created an array of teams but the indices of these are all numerical. You’re attempting to access this table via the indice of the player’s team name which will be nil. For this to work, the indices need to be strings and the value needs to be non-nil. See example [1] for a fixed version.
-
The third sample also will not work the way you intend because “White” is not a property of “Name”. You’d need to use the == operator (is equal to) for this instead. See example [2].
[1]:
local onlyTeams = {
["Green"] = true,
-- same for the rest of the teams
}
if onlyTeams[player.Team.Name] then
-- Commit action
end
* table.find is acceptable as well, but you need to be aware of what value types you’re including in the table. The original organisation of the table is invalid since a player cannot be on multiple teams at once.
[2]:
if not (player.Team.Name == "White") then
-- Commit action
end
* The parenthesis are required to define what you’re checking which then the not operator flips the result of the evaluation in the parenthesis. Alternatively, you can use the ~= (not equal to) operator and avoid using not. A common mistake is not to include these in parenthesis; the not would only act on the left-hand operand not the whole evaluation.
if player.Team.Name ~= "White" then
-- Commit action
end
whoops agree on the last one gonna fix it also thx for feedback and what is