如何将 Lua 正则表达式添加到此部分中?

我有一个类似于 ID:MeshID =="rbxassetid://2542637991"的代码,那么我应该怎样做才能使用"MeshID =="rbxassetid://XY" then"在 lua 中,因此不需要添加确切的数字?

if Stuff:IsA("MeshPart") then
            if MeshID == "rbxassetid://NUMBER" then
                local Distance = game.Players.LocalPlayer:DistanceFromCharacter(Stuff.Position)
                if Distance < least and Distance < 250 then
                    least = Distance
                    Object = Stuff
                end

要在 NUMBER 中添加在代码中找到的数字。

点赞
用户1442917
用户1442917

你可以使用 match 函数来找到你需要的值:

如果 Stuff:IsA("MeshPart") then
  local num = tonumber(MeshID:match("rbxassetid://(%d+)"))
  if num then -- 这将替换 `MeshID == "rbxassetid://NUMBER"` 检查
2018-12-21 23:35:42