语法错误:(10,2) 预期标识符,得到了’if’ 在ROBLOX STUDIO中。

huangapple go评论58阅读模式
英文:

Syntax Error: (10,2) Expected identifier, got 'if' In ROBLOX STUDIO

问题

以下是您提供的代码的翻译部分:

我正在创建一个游戏需要消灭一群海盗但当我运行此脚本时出现错误
> 语法错误(10,2) 预期标识符得到了 'if'

请注意,您提供的代码在许多地方都存在问题,需要进行修复。如果您需要有关如何修复这些问题的建议,请告诉我,我将为您提供进一步的帮助。

英文:

I am creating a game in which you need to kill a bunch of Pirates, but the error:
>Syntax Error: (10,2) Expected identifier, got 'if'

appears when I run this script (code below):

dead_bool = game.ServerScriptService.deadBool.Value
print(dead_bool)

NPC_died = 0

while true do
	wait(0.1)
	local killed = game.Players.
	
	if script.Parent.Humanoid ~= nil then
		if script.Parent.Humanoid.Health <=0 then
			NPC_died.Value += 1
			dead_bool = true
			if dead_bool then
				kills.Value +=1
				wait(0.1)
				script:remove()
			end
		end
	end
end

And yeah the dead_bool value is in the right place so yeah please help.

it was supposed yo display as either true or false but its giving me an error, just please help fix it..

答案1

得分: 0

错误是因为你的代码中有语法错误。在Lua中,你需要在 local killed = game.Players. 这一行之后提供一个标识符(变量名)。目前,由于缺少标识符,导致了语法错误。

以下是已纠正的代码版本:

local dead_bool = game.ServerScriptService.deadBool.Value
print(dead_bool)

local NPC_died = 0

while true do
    wait(0.1)
    local killed = game.Players.LocalPlayer -- 在这里添加一个标识符

    if script.Parent.Humanoid ~= nil then
        if script.Parent.Humanoid.Health <= 0 then
            NPC_died.Value += 1
            dead_bool = true
            if dead_bool then
                kills.Value += 1
                wait(0.1)
                script:remove()
            end
        end
    end
end

在已纠正的代码中,我添加了 LocalPlayer 作为 game.Players. 的标识符。你可以根据需要进行修改。

另外,请注意,NPC_died 被赋值为0,但在你的代码后面,你试图增加 NPC_died.Value 的值,就好像它是一个Roblox数据存储对象。如果你打算使用数据存储,请确保正确处理它并正确初始化。

英文:

The error you is having is is becaus is a syntax error is in your code. Is in is LuaUU, you need to provide an identifier (a variable name) after the local killed = game.Players. line. Currently, there is a missing identifier, causing the syntax error.

Here's the corrected version of your code:

local dead_bool = game.ServerScriptService.deadBool.Value
print(dead_bool)

local NPC_died = 0

while true do
    wait(0.1)
    local killed = game.Players.LocalPlayer -- Add an identifier here

    if script.Parent.Humanoid ~= nil then
        if script.Parent.Humanoid.Health &lt;= 0 then
            NPC_died.Value += 1
            dead_bool = true
            if dead_bool then
                kills.Value += 1
                wait(0.1)
                script:remove()
            end
        end
    end
end

In the corrected code, I added LocalPlayer as the identifier for game.Players.. You can modify it according to your requirements.

Additionally, note that NPC_died is assigned a value of 0, but later in your code, you're trying to increment NPC_died.Value as if it were a Roblox DataStore object. If you intended to use a DataStore, make sure to properly handle it and initialize it correctly.

huangapple
  • 本文由 发表于 2023年7月18日 15:22:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76710359.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定