Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Roblox's transition between Lua and Luau (I'm new). What are some good sites to learn Luau?

Asked by 3 years ago

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)

4 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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.

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)
Log in to vote
0
Answered by
Speedmask 661 Moderation Voter
3 years ago
Edited 3 years ago

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 jazz
  • continue keyword, if you have used other languages you know it’s like break but just skips to the next iteration of a loop
  • type annotations, for now they just give lint errors in studio but I think they plan on changing that. probably the biggest change, but not even necessary to use at all. this includes two new keywords type and export.
  • probably doesn’t count as part of the language but you’ve got a hell of a lot more globals like newproxy and workspace, there is a list somewhere online
  • random optimizations, not sure if they exist in lua but for example you don’t have to define built in modules as locals to make it faster anymore (if you don’t know what I mean then forget about it)
  • lots and lots of sandboxing, you can’t use most of the stuff in the os library for example

tips that could trip up lua users:

  • don’t use type, use typeof for roblox objects
  • always disconnect Connection objects
  • use RunService for very fast loops, never Wait (another new roblox global)

Answer this question