what I'm trying to do is to get the distance from chracters torso to the block. I don't know why, but when im referencing the folder, it gives that error.
this is the error code: Workspace.Gromaniak85.LocalScript:7: Expected ')' (to close '(' at column 25), got '.2xblock'
local DistanceRemote = game:GetService("ReplicatedStorage").DistanceFromBlock
local player = script.Parent.Parent
local BrickMultipliers = game.Workspace.BrickMultipliers
while true do
wait(0.5)
local distancefrom2x = (game.Workspace[player.Name].UpperTorso.Position - BrickMultipliers.2xblock.Position).magnitude --error happens there
print(distancefrom2x)
end
Here it's how it is in studio:
https://i.sstatic.net/pTMar.png
I don't really know what to do, so I'll be thankfull for all help !!
According to Lua's lexical conventions a name may not begin with a digit!
Names (also called identifiers) in Lua can be any string of Latin letters, Arabic-Indic digits, and underscores, not beginning with a digit and not being a reserved word. Identifiers are used to name variables, table fields, and labels.
The following keywords are reserved and cannot be used as names:
and break do else elseif end false for function goto if in local nil not or repeat return then true until while
Hence this is invalid syntax: BrickMultipliers.2xblock.Position
From Lua 5.4 Reference Manual 3.2 - Variables:
The syntax var.Name is just syntactic sugar for var["Name"]:
var ::= prefixexp ‘.’ Name
So this convenient syntax only works for Lua identifiers (names).
As 2xblock
begins with a digit so it cannot be a name. Thus BrickMultipliers.2xblock
causes an error.
For any table key that is not a Lua name you have to use the square bracket notation.
BrickMultipliers["2xblock"]