I’ve already browsed the DevHub but I wanna see if anyone else can explain it a little better. This is an excerpt from a script I found:
local PlayerRunning = {}
sprintingPlayers[player.Name] = humanoid.WalkSpeed
humanoid.WalkSpeed = humanoid.WalkSpeed * sprintModifier
elseif state == "Ended" and sprintingPlayers[player.Name] then
humanoid.WalkSpeed = sprintingPlayers[player.Name]
sprintingPlayers[player.Name] = nil
How does the script know what the humanoid walkspeed is from the bracket “Player.Name” alone? Previously the dictionary or table (if there’s a difference between the 2, let me know) isn’t clearly defined.
Another time it’s used in the script is here:
local name = player.Name
player.Character.Humanoid.WalkSpeed = sprintingPlayers[name]
Here it’s setting the Humanoid’s WalkSpeed to the player’s name? What’s up with that? Nice detailed explanation of how they work would be nice.
This is setting a key-value pair, the player’s name being the key, mapped to the walk speed, which is the value. Indexing a table with a key returns the value, not the key.
So this is setting their walk speed to whatever number the player’s name is mapped to in the table.
To add up, it’s not kinda like the same. table.insert is meant to insert a value to a table, while table[] on dictionaries do is index an existing key to get the key’s value or create a new key name.