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

How to fix this error?

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)

2 comments

0

Could you provide the exact error and line?

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.

1 answer

✓ Accepted answer

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.

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