Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Expected end to close function near elseif, how to fix this?

Asked by 7 years ago

Hello,

I'm making a script, once they have been clicked, they have been selected. But the problem is... This script is acting weird. And saying it is missing a end for the function. But I ended it.

This error I got

'end' expected (to close 'function' at line 7) near 'elseif'

Here is the script.

local mouse = game.Players.LocalPlayer:GetMouse()
target1 = nothing
target2 = nothing
target3 = nothing
target4 = nothing
target5 = nothing
mouse.Button1Down:connect(function()
    local part = mouse.Target
    if part.Parent:FindFirstChild("Humanoid") ~= nil then
        print("Humanoid!")
        local humanoid = part.Parent:FindFirstChild("Humanoid") 
        if script.Bools.Target1.Value == false then
            target1 = part.Parent.Name
            script.Bools.Target1.Value = true
            script.Bools.Target1.TargetName.Value = (part.Parent.Name)
            end
        elseif
            script.Bools.Target2.Value == false then
            if part.Parent.Name == target1 then end
             else
                target2 = part.Parent.Name
                script.Bools.Target2.Value = true
                script.Bools.Target2.TargetName.Value = (part.Parent.Name)
                end
            elseif
                script.Bools.Target3.Value == false then
                if part.Parent.Name == target1 or target2 then end
                else
                    target3 = part.Parent.Name
                    script.Bools.Target3.Value = true
                    script.Bools.Target3.TargetName.Value = (part.Parent.Name)
                    end
                elseif
                    script.Bools.Target4.Value == false then
                    if part.Parent.Name == target1 or target2 or target3 then end
                    else
                        script.Bools.Target4.Value = true
                        script.Bools.Target4.TargetName.Value = (part.Parent.Name)
                        end
                    elseif
                        script.Bools.Target5.Value == false then
                        if part.Parent.Name == target1 or target2 or target3 or target4 then end
                        else
                            target5 = part.Parent.Name
                            script.Bools.Target5.Value = true
                            script.Bools.Target5.TargetName.Value = (part.Parent.Name)
                            end
        else
        print("What is this?")
    end
end)

could you help me?

1 answer

Log in to vote
0
Answered by
Tesouro 407 Moderation Voter
7 years ago

Well, it's most a matter of organization, so you can find the missing ends and fix your if conditions. But I think you should get to know Conditional statements better, because this script is pretty messed up.

I didn't get the purpose of these many conditions, but I organized and fixed your script as I usually do. So, a working code would look like this:

local mouse = game.Players.LocalPlayer:GetMouse()
target1 = nothing
target2 = nothing
target3 = nothing
target4 = nothing
target5 = nothing
mouse.Button1Down:connect(function()
    local part = mouse.Target

    if part.Parent:FindFirstChild("Humanoid") ~= nil then
        print("Humanoid!")
        local humanoid = part.Parent:FindFirstChild("Humanoid") 
    end -- missing end

    if script.Bools.Target1.Value == false then
        target1 = part.Parent.Name
        script.Bools.Target1.Value = true
        script.Bools.Target1.TargetName.Value = (part.Parent.Name)
    elseif -- the elseif is in the if block
        script.Bools.Target2.Value == false then
    end -- missing end

    if part.Parent.Name == target1 then
        -- something here
    elseif
        script.Bools.Target3.Value == false then
    else -- you should put the else last
        target2 = part.Parent.Name
        script.Bools.Target2.Value = true
        script.Bools.Target2.TargetName.Value = (part.Parent.Name)
    end

    if part.Parent.Name == target1 or target2 then
        -- something here
    elseif script.Bools.Target4.Value == false then
        -- something here
    else
        target3 = part.Parent.Name
        script.Bools.Target3.Value = true
        script.Bools.Target3.TargetName.Value = (part.Parent.Name)
    end

    if part.Parent.Name == target1 or target2 or target3 then
        -- something here
    elseif
        script.Bools.Target5.Value == false then
    else
        script.Bools.Target4.Value = true
        script.Bools.Target4.TargetName.Value = (part.Parent.Name)
    end

    if part.Parent.Name == target1 or target2 or target3 or target4 then
        -- something here
    else
        target5 = part.Parent.Name
        script.Bools.Target5.Value = true
        script.Bools.Target5.TargetName.Value = (part.Parent.Name)
    end
end)
Ad

Answer this question