I am trying to make a SurfaceGui shop that gets all items in a Folder, clones the frame and changes the frame.ItemName(TextLabel).Text to the name of it. But for some reason I can't get this script to work.

local sp = script.Parent
local folder = sp.ScrollingFrame
local player = script.Parent.Parent.Parent.Parent

function refresh()
	folder:ClearAllChildren()
	for _,item in pairs(game.ServerStorage.ShopItems:GetChildren()) do 
		local frame = script.Frame:Clone()
		frame.Parent = folder
		frame.ItemName.Text = item.Name " : "..item.Price.Value..""
		frame.Name = item.Name
		frame.Purchase.MouseButton1Click:connect(function(c)
			if player:FindFirstChild("globalstats").Points.Value < item.Price.Value
				then
				return false
			else
				player:FindFirstChild("globalstats").Points.Value = player:FindFirstChild("globalstats").Points.Value - item.Price.Value
				local itemt = item.Tool:Clone()
				itemt.Parent = player.Backpack
				itemt.Name = item.Name
			end
		end)
	end
end

game.Players.PlayerAdded:connect(function(p)
	wait(1)
	refresh()
end)

Output show's no error's, can anyone tell me why it won't work?

6 comments

0

Remove line 4 and try it.

0

Nope, still won't work.

0

Try removing the argument "c" on line 12.

0

xJasonn: Don't give speculative advice as comments. Submit an answer if you have a solution.

0

Have you done any debugging? Have you checked that refresh is in fact called when a new player joins by seeing a print happen?

0

Still does not work.