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

How to fix this error?

Asked by 8 years ago

I am trying to make a SurfaceGui ScrollingFrame Shop, and this script tell's me there is a error between 12 and 23(Between MouseButton1Click and end. Can anyone tell me how to fix the error?

gather = game.ServerStorage.GearStorage:GetChildren()
scroll = script.Parent.ScrollingFrame
player = script.Parent.Parent.Parent


for i,v in pairs(gather) do
    local frame = script.Template:Clone()
    frame.Name = v.Value
    frame.Parent = scroll
    frame.Position = frame.Position + UDim2.new(0,0,0,35*i)
    frame.ItemName.Text = v.Value.." | "..v.Price.Value
    frame.Purchase.MouseButton1Click:connect(function(c)
        if player.globalstats.Points.Value < v.Price.Value then
            print(player.Name.." can not afford "..v.Value.."")
        else
            player.globalstats.Points.Value = player.globalstats.Points.Value - v.Price.Value
            local tool = v.Tool:Clone()
            tool.Parent = player.Backpack
            tool.Name = v.Value 
        end
    end
end)
0
Could you provide the exact error and line? Goulstem 8144 — 8y
0
I did, between 12 and 23. It show's a red line under it and the script doesn't run but there is no error in output. ISellCows 2 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

You have your parenthesis for closing the event connection on line 12 in the wrong place. You should have the closing parenthesis after the second to last end of your script. You are putting it on the last end where the for loop ends.

Overall, your script should look like this:

gather = game.ServerStorage.GearStorage:GetChildren()
scroll = script.Parent.ScrollingFrame
player = script.Parent.Parent.Parent


for i,v in pairs(gather) do
    local frame = script.Template:Clone()
    frame.Name = v.Value
    frame.Parent = scroll
    frame.Position = frame.Position + UDim2.new(0,0,0,35*i)
    frame.ItemName.Text = v.Value.." | "..v.Price.Value
    frame.Purchase.MouseButton1Click:connect(function(c)
        if player.globalstats.Points.Value < v.Price.Value then
            print(player.Name.." can not afford "..v.Value.."")
        else
            player.globalstats.Points.Value = player.globalstats.Points.Value - v.Price.Value
            local tool = v.Tool:Clone()
            tool.Parent = player.Backpack
            tool.Name = v.Value 
        end
    end) --Closing parenthesis here to close the event connection on line 12.
end

I hope my answer helped you. If it did, be sure to accept it.

Ad

Answer this question