Roblox - 'then' 期望在 'local' 附近

我的 Roblox 脚本出现了一个错误,我不知道它是什么意思。

它说 line 7 [7: 0] 'then' expected near 'local'

local name = "" -- 在这里放置柠檬水/热狗摊主的名字

local owner = game:GetService("Players")[name]

for i,v in pairs(game.ReplicatedStorage.API:GetChildren()) do
    if v:IsA("RemoteFunction")
        local A_1 = "lemonade_stand" -- 如果是热狗摊,则更改为 hotdog_stand
        local A_2 = owner
        v:InvokeServer(A_1, A_2)
    end
点赞
用户6605392
用户6605392

你需要在 if-then 语法规范中添加 then,并且你需要另一个 end 来关闭 for 循环:

local name = "" -- 在这里放柠檬水或热狗摊主的名字

local owner = game:GetService("Players")[name]

for i,v in pairs(game.ReplicatedStorage.API:GetChildren()) do
  if v:IsA("RemoteFunction") then
    local A_1 = "lemonade_stand" -- 如果是热狗摊,则改为 hotdog_stand
    local A_2 = owner
    v:InvokeServer(A_1, A_2)
  end
end
2020-08-27 10:54:40
用户14717524
用户14717524

这个错误意味着你缺少让脚本正常运作的必要条件。

在编写条件/语句时,你必须在条件后面放置then。为什么?把语法看作是让脚本有意义的方法。

你的循环结尾也缺少end。别忘了这个!

下面已经修复了你的脚本。记住,当Lua期望某些情况时,这是一个语法错误。

local Name = ''

for i,v in pairs(game.ReplicatedStorage.API:GetChildren()) do
    if v:IsA("RemoteFunction") then
        v:InvokeServer('lemonade_stand', game.Players[Name]) -- 或者你可以使用game.Players.LocalPlayer[PlayerName],这更简单。
    end
end
2020-12-18 23:17:56
用户14152585
用户14152585

你忘记在 if v:IsA('RemoteEvent') 后面添加 "then"。在 Lua 中,条件语句总是这样开始的:

local yourcondition = true

if yourcondition then
    print("yourcondition is true!")
end

这是一个有点愚蠢的错误,但你应该始终在在此之前查看 Roblox 显示的错误,而不是在这里输入你的问题。这可以很容易地使用 Output 窗口解决。 (View -> Output) 这就是语法如何工作的方式。把 LUA 解释器当作你的英语老师。如果你没有按照英语的语法要求做,则老师会告诉你你犯了一个错误。

2021-02-01 05:18:07
用户16639745
用户16639745
local name = "" -- 在这里输入柠檬水摊/热狗摊老板的名字

local owner = game:GetService("Players")[name]

for i,v in pairs(game.ReplicatedStorage.API:GetChildren()) do
    if v:IsA("RemoteFunction") then -- 在这里忘记加上"then"
        local A_1 = "lemonade_stand" -- 如果是热狗摊则改为"hotdog_stand"
        local A_2 = owner
        v:InvokeServer(A_1, A_2)
    end
end -- 最后一行少了一个"end"
2021-08-11 09:23:49