Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Line 26 "Expected identifier when parsing expression,got "~=" how to fix?

i tried taking a damage script and tried to edit it so instead of taking damage,you get kicked, i've been trying alot to fix this error how i fix it?

local lleg = script.Parent:FindFirstChild("Torso")
local rleg = script.Parent:FindFirstChild("Head")
 
function findNearestTorso(pos)
    local list = game.Workspace:children()
    local torso = nil
    local dist = 1000
    local temp = nil
    local human = nil
    local temp2 = nil
    for x = 1, #list do
        temp2 = list[x]
        if (temp2.className == "Model") and (temp2 ~= script.Parent) then
            if (temp ~= nil) and (human ~= nil) and (human:remove()) then
                if (temp.Position - pos).magnitude < dist then
                    torso = temp
                    dist = (temp.Position - pos).magnitude
                end
            end
        end
    end
    return torso
end
 
function onTouch(hit)
   game.Players:FindFirstChild(hit.Parent.Name) ~= nil then ----the error gets here
		human = game.Players:FindFirstChild(hit.Parent.Name)
		human:Kick("kick")
	end
end

script.Parent.Touched:Connect(onTouch)
 
lleg.Touched:connect(Hit)
rleg.Touched:connect(Hit)

2 comments

0

This Script is horribly wrong, please explain what you're trying to do, so I can provide you with something functional

0

he forgot the if on line 26

2 answers

Resolving Deprecation Issues:

After analyzing most of your code, It is quite noticeable this program is either very old, or just applies a numerous amount of deprecated practices. If an item is deprecated, it becomes unsupported by the Game Engine, and superseded by another alternative method designed to work best with the updated API.

It is advised that you disregard all predecessors as using them can cause mild to severe performance issues.


Let's take a look at all the deprecated methods you have, and which have taken their place:

methods of Instance:

  1. :children() — :GetChildren()

  2. :remove() — :Destroy()/:ClearAllChildren()

methods of RBXScriptSignal:

  1. :connect() — :Connect()

Addressing Your Errors:

Your Script contains a ton of unnecessary code as well. Practically all the issues I brought up above are just caused by a tracing function, that isn't even used. You can go straight away and remove it.

The central problem you're running into is a syntax error. The ~=—not equal-to—operator is a Boolean expression evaluator; this operator is used to compare two tokens for no similarity, therefore must be used in a conditional environment. You were halfway there, the obstacle was a malformed if statement. Though, it isn't even needed with a few adjustments:

local Players = game:GetService("Players")

local Character = script.Parent

local function OnTouch(Hit)
	local Humanoid = Hit.Parent:FindFirstChildOfClass("Humanoid")
	if (Humanoid) then
		local Player = Players:GetPlayerFromCharacter(Hit.Parent)
		Player:Kick("You got kicked!")
	end
end

Character.Touched:Connect(OnTouch)

So when you get a expected identifier error in your output it always means that you either missed a symbol it gave you or you put something there that you can't use.

So in this case it told you the symbol was "~=" and it said that you put it there on line 27. If you look on line 26 if your script you posted there is a ~=.

You can only use ~= when dealing with if statements or conditions. So there should be an if statement there cause you are trying to check if it's nil.

Ignoring the other stuff that is wrong with the code.... Here is the fix to your specific error:

if game.Players:FindFirstChild(hit.Parent.Name) ~= nil then
	-- stuff that you want to run if it is not nil.
end

Another way of checking if something isn't nil is to say

if game.Players:FindFirstChild(hit.Parent.Name) then
	-- stuff you want to run if it is not nil
end

This did answer your question on the error. I do not need to fix your other code issues since you asked about the error lol.

This discussion is preserved as it was. New answers, comments, and votes are closed.