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..
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 <= 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.