Suddenly by shop pad isn't working for whatever reason

I’m working on creating my ability upgrades for my game but I realize my shop is a little broken so I have to fix it.

I’m also adding an upgrade button so you can upgrade abilities in the game.

There are 2 problems.

When you step on the shop pad everything on the server works but when you fire to the client for the shop to be enabled, nothing happens.

The initializing for the inside of the shop ui doesn’t work either.

Server
workspace.ShopPad.Touched:Connect(function(hit)
	local character = hit.Parent
	local player = Players:GetPlayerFromCharacter(character)
	if player and not PlayersInShop[player] then
		local humanoid = character:FindFirstChild("Humanoid")
		PlayersInShop[player] = player
		Controls(humanoid,0,0,false)
		Remotes.ToClient:FireClient(player,"EnableShop")
	end
end)
Client
task.wait(1)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage.Remotes
local Assets = ReplicatedStorage.Assets
local Functions = ReplicatedStorage.Functions
--Vars--
local Select = script.Select

local ShopGui = script.ShopGui
local ExitButton = ShopGui.ExitButton
local ShopFrame = ShopGui.ShopFrame
local Items = ShopFrame.Backdrop.Items
local SelectBox = ShopFrame.SelectBox
--
local currentC
local currentU

local function Clear()
	for i,v in SelectBox:GetChildren() do if not v:IsA("UICorner") then v:Destroy() end end
end

local function UpdateText(text,message,t)
	task.spawn(function()
		text.Text = message
		task.wait(t)
		text.Text = "Buy"
	end)
end

local function click(btn,title)
	if btn:GetAttribute("Enabled") == true then return end
	btn:SetAttribute("Enabled",true)
	local invoke = Functions.Purchase:InvokeServer(title)
	if invoke == "Success" then
		btn.Text = "Equipped"
	elseif invoke == "Failure" then
		UpdateText(btn,"Not enough money!",2)
	elseif invoke == "Bought" then
		UpdateText(btn,"You already purchased!",2)
	elseif invoke == "Equip" then
		btn.Text = "Equipped"
	end
	task.wait(1)
	btn:SetAttribute("Enabled",false)
end


local function Swap(image,title)
	local tt = SelectBox:FindFirstChild("Title")
	local btn = SelectBox:FindFirstChild("BuyButton")
	tt.Text = title
	if currentC then currentC:Disconnect() end
	if currentU then currentU:Disconnect() end
	currentC = btn.MouseButton1Up:Connect(function()
		click(btn,title)
	end)
end

local function clean(image,ability)
	local title = SelectBox:FindFirstChild("Title")
	if title and title.Text == ability.Name then Clear() return end
	if title and title.Text ~= ability.Name then Swap(image,ability.Name) return end
end

local function create(ability)
	local newSelect = Select:Clone()
	local update = Functions.Update:InvokeServer("BuyButton",ability.Name)
	print(update)
	if update == "Equipped" or update == "Equip" then
		newSelect.UpgradeButton.Visible = true
		currentU = newSelect.UpgradeButton.MouseButton1Up:Connect(function()
			local enabled = newSelect.UpgradeButton:GetAttribute("Enabled")
			if enabled then
				newSelect.UpgradeButton:SetAttribute("Enabled",false)
				local invoke = Functions.UpgradeAbility:InvokeServer(ability.Name)
				task.wait(2)
				newSelect.UpgradeButton:SetAttribute("Enabled",true)
			end
		end)
	end
	newSelect.Title.Text = ability.Name
	newSelect.BuyButton.Text = update
	currentC = newSelect.BuyButton.MouseButton1Up:Connect(function()
		click(newSelect.BuyButton,ability.Name)
	end)
	newSelect.Parent = SelectBox
end


for _,ability in Assets.Shop:GetChildren() do
	if ability:IsA("ModuleScript") then return end
	local image = ability:GetAttribute("ShopImage")
	local price = ability:GetAttribute("Price")
	local imageB = Instance.new("ImageButton") -- image later
	
	imageB.Parent = Items
	imageB.MouseButton1Up:Connect(function()
		clean(image,ability)
		create(ability)
	end)
end

ExitButton.MouseButton1Up:Connect(function()
	ShopGui.Enabled = false
	Clear()
	Remotes.ToServer:FireServer("UnenableShop")
end)

Remotes.ToClient.OnClientEvent:Connect(function(signal)
	if signal == "EnableShop" then
		ShopGui.Enabled = true
	end
end)

I noticed that here in my client code, it won’t print inside the loop nor after it. But it will work with anything before.

Success - does not print

For loop before everything - prints

for i,v in Assets.Shop:GetChildren() do
	print(i,v)
end


for _,ability in Assets.Shop:GetChildren() do
	if ability:IsA("ModuleScript") then return end
	local image = ability:GetAttribute("ShopImage")
	local price = ability:GetAttribute("Price")
	local imageB = Instance.new("ImageButton") -- image later

	imageB.Parent = Items
	imageB.MouseButton1Up:Connect(function()
		clean(image,ability)
		create(ability)
	end)
end


print("Success")

Somehow the 2nd loop prints nothing, but the 1st for loop prints everything, the shop folder is filled with a bunch of folders containing attributes on what to purchase.

Nevermind I see my issue, I used return end, I should’ve used continue end.

Return end completely ends the entire loop.

I also put it inside a task.spawn to not ruin code after it like the signal for enabling the shop gui.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.