I'm new to roblox scripting and I know that they use LUA. But I have learned that they now use luau, and making some if no most of their tutorials useless. Anyone know good free sites to learn luau?
I tried making a kill part, but failed
local lava = script.Parent
local function killPlayer(otherPart) local partParent = otherPart.Parent local humanoid = partParent:FindFirstChild("Humanoid") if humanoid then
end
end
lava.Touched:Connect(killPlayer)
Luau is almost the same as Lua. The syntax of the language hasn't changed. Some things have been added such as these operators +=, -=, *=, /= and almost no FilteringEnabled tutorials have become useless since Roblox has started using Luau.
I think this code should work, I'm not sure though since I can't test it right now.
local lava = script.Parent local function killPlayer(hit) local partParent = hit.Parent local Humanoid = partParent:FindFirstChildWhichIsA("Humanoid") if Humanoid then Humanoid.Health = 0 end end lava.Touched:Connect(killPlayer)
Most of what you need to know can be found at https://luau-lang.org/syntax
Any Roblox Lua script is still fully compatible with Luau, so all tutorials are still valid.
For "strict" mode, one thing I recently found out (that is not currently documented at that site) is that if you want to type-cast (to tell Roblox the type of some value), you need to use ::
, such as in:
--!strict local function describe(x:Instance, isBasePart:boolean?) if isBasePart then print(x.Name, x.Transparency) -- Warning will show up: Key 'Transparency' not found in class 'Instance' print(x.Name, (x::BasePart).Transparency) -- No warning because we're telling Roblox it's a BasePart and it knows that BaseParts have .Transparency else print(x.Name) end end describe(workspace) describe(workspace.Baseplate, true)
If you are using strict mode, the Script Analysis window will be likely to tell you if something doesn't look right, which can help prevent errors, once you learn how to use it. Tip: you can say that something is of type any
to silence type warnings on certain variables while keeping type checking for the rest of the script.
A good place to learn Lua is here but I don’t know the computer language Luau. And here’s a script on a instant kill brick that will work when CanCollide is false:
script.Parent.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild(“Humanoid”) if hit.Parent ~= humanoid then humanoid.Health = 0 end end)
yeah like other people said it’s pretty much the same thing, changes are quite small. it uses lua 5.1 so some stuff from the newer lua versions aren’t in roblox (goto
for example).
another person posted the link that you should check, that’s the only reference you need. here are some quick highlights I can recall from the top of my head.
+=
, *=
, you know that jazzcontinue
keyword, if you have used other languages you know it’s like break
but just skips to the next iteration of a looptype
and export
.newproxy
and workspace
, there is a list somewhere onlineos
library for exampletips that could trip up lua users:
type
, use typeof
for roblox objectsConnection
objectsRunService
for very fast loops, never Wait
(another new roblox global)