i keep geting the error expected identifier and i dont know what that means

21 views Asked by At

here is the script im working on

modelname="players"
function onTouched(hit)
    if not hit or not hit.Parent then return end
    local human = hit.Parent:findFirstChild("Humanoid")
    if human and human:IsA("Humanoid")and if game.Players:playerFromCharacter(hit.Parent).TeamColor==game.Teams:findFirstChild(modelname).TeamColor then 
       human:TakeDamage(100)
    else 
    end
end


script.Parent.Touched:connect(onTouched)

i just need someone to explain what it wants when it says there error message

1

There are 1 answers

0
justadev On

In the if statement, there are two if keywords. This is most likely the source of the error. To fix it, remove the second if.

Fixed function

function onTouched(hit)
    if not hit or not hit.Parent then return end
    local human = hit.Parent:findFirstChild("Humanoid")
    if human and human:IsA("Humanoid") and game.Players:playerFromCharacter(hit.Parent).TeamColor == game.Teams:findFirstChild(modelname).TeamColor then 
       human:TakeDamage(100)
    end
end

If nothing is happening in the else statement, it can be safely removed. Add it back if you have to though.

The error is basically lua expecting more than what was given, in this case a block of code defined in a then-end block.