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

how do i fix expected identifier error?

Asked by 3 years ago
Edited 3 years ago
local Arrow = script.Parent
local Click = Arrow:WaitForChild("Click")

Click.MouseClick:Connect(function(player,tool)

    local Backpack = player:FindFirstChild("Backpack")

    local randomStand = math.random(1,3) --1 to the number of stands you have
end 


    if Backpack then
        if randomStand == 1 then
            local Stands = game:GetService("ServerStorage"):WaitForChild("Stands")

            --//If stand is summoned
            local prevStand = workspace:FindFirstChild(player.Name.." Stand")
            if prevStand then
                prevStand:Destroy()
            end

            for i, v in pairs(Backpack:GetChildren()) do
                if v:IsA("Folder") then
                    local StandSummon = v:FindFirstChild("StandSummon")
                    if StandSummon then
                        v:Destroy()
                    end
                end
            end

            --//Stand will be given
            local Stand = Stands:FindFirstChild("Stand1"):Clone()
            Stand.Parent = Backpack

            local plrstats = player:FindFirstChild("PlrStats")
            if plrstats then
                local currentstand = plrstats:FindFirstChild("Stand")
                currentstand.value ="Stand1"

            Arrow:Destroy()
        elseif randomStand == 2 then
            local Stands = game:GetService("ServerStorage"):WaitForChild("Stands")

            --//If stand is summoned
            local prevStand = workspace:FindFirstChild(player.Name.." Stand")
            if prevStand then
                prevStand:Destroy()
            end

            for i, v in pairs(Backpack:GetChildren()) do
                if v:IsA("Folder") then
                    local StandSummon = v:FindFirstChild("StandSummon")
                    if StandSummon then
                        v:Destroy()
                    end
                end
            end

            --//Stand will be given
            local Stand = Stands:FindFirstChild("Stand2"):Clone()
            Stand.Parent = Backpack

            local plrstats = player:FindFirstChild("PlrStats")
            if plrstats then
                local currentstand = plrstats:FindFirstChild("Stand")
                currentstand.value ="Stand2"

            end
            Arrow:Destroy()
        elseif randomStand == 3 then
            local Stands = game:GetService("ServerStorage"):WaitForChild("Stands")

            --//If stand is summoned
            local prevStand = workspace:FindFirstChild(player.Name.." Stand")
            if prevStand then
                prevStand:Destroy()
            end

            for i, v in pairs(Backpack:GetChildren()) do
                if v:IsA("Folder") then
                    local StandSummon = v:FindFirstChild("StandSummon")
                    if StandSummon then
                        v:Destroy()
                    end
                end
            end

            --//Stand will be given
            local Stand = Stands:FindFirstChild("Stand3"):Clone()
                Stand.Parent = Backpack

                local plrstats = player:FindFirstChild("PlrStats")
                if plrstats then
                    local currentstand = plrstats:FindFirstChild("Stand")
                    currentstand.value ="Stand3"
                    end

            Arrow:Destroy()
        end
    end
end

Line 4

ERROR:Error: (12,2) Syntax error: Expected ')' (to close '(' at line 4), got 'if'

0
Add a parenthesis at line 9 end) JesseSong 3916 — 3y

1 answer

Log in to vote
0
Answered by
R_alatch 394 Moderation Voter
3 years ago

For starters, you never close the Connect on line 4. Secondly, the if statement and everything inside should be inside that same function. Finally, repeating the entire code 3 times inside if statements was completely unnecessary since you can just concatenate the random stand that was chosen.

I have renamed some variables and fixed the script:

local arrow = script.Parent
local click = arrow:WaitForChild("Click")

local stands = game:GetService("ServerStorage"):WaitForChild("Stands")

click.MouseClick:Connect(function(player, tool)
    local randomStand = math.random(1, 3)

    local backpack = player:FindFirstChild("Backpack")

    if backpack then
        local prevStand = workspace:FindFirstChild(player.Name .. " Stand")

        if prevStand then
            prevStand:Destroy()
        end

        for _, v in pairs(backpack:GetChildren()) do
            if v:IsA("Folder") then
                local StandSummon = v:FindFirstChild("StandSummon")

                if StandSummon then
                    v:Destroy()
                end
            end
        end

        local stand = stands["Stand" .. randomStand]:Clone()
        stand.Parent = backpack

        local playerStats = player:FindFirstChild("PlrStats")

        if playerStats then
            playerStats.Stand.currentstand.Value = "Stand" .. randomStand

            arrow:Destroy()
        end
    end
end)
0
no Not_prototype 50 — 3y
Ad

Answer this question