Why wont this work to detect a button click

local Ordering = game.StarterGui:WaitForChild("GuiOrdering"):WaitForChild("Main"):WaitForChild("Items")
local Event = game.ReplicatedStorage:WaitForChild("Order")

for _, v in Ordering:GetChildren() do
	if v:IsA("Frame") then
		print(v.Name)
		print("Sent, "..v.Name..v.Price.Text)
		v.Purchace.MouseButton1Click:Connect(function()
			print("Sent, "..v.Name..v.Price.Text)
			print("Sent, "..v.Name..v.Price.Text)
			print("Sent, "..v.Name..v.Price.Text)
			Event:Fire(v.Name, v.Price.Text)
			print("Sent, "..v.Name..v.Price.Text)
		end)
	end
end

idk what im doing wrong but nothing is working and there are no errors

3 Likes

This should work:

for _, v in pairs(Ordering:GetChildren()) do
	if v:IsA("Frame") then
		print(v.Name)
		print("Sent, "..v.Name..v.Price.Text)
		v.Purchace.MouseButton1Click:Connect(function()
			print("Sent, "..v.Name..v.Price.Text)
			print("Sent, "..v.Name..v.Price.Text)
			print("Sent, "..v.Name..v.Price.Text)
			Event:Fire(v.Name, v.Price.Text)
			print("Sent, "..v.Name..v.Price.Text)
		end)
	end
end``

thats not working still, and no errors

v.Purchace.MouseButton1Click:Connect(function()<
Did you misspell Purchase?

It would be easier to help you if you could send a screenshot of your ui setup, like:
image

And you do mention that you do not see any errors, but could it be that you have an infinite yield on :WaitForChild()? They may take longer than an error to appear. I am referring to this:

local Ordering = game.StarterGui:WaitForChild("GuiOrdering"):WaitForChild("Main"):WaitForChild("Items")
local Event = game.ReplicatedStorage:WaitForChild("Order")

its ok, i think im gonna give up on this game for now. Im new to coding and this game is too advanced rn for me

It’s best to start slow, and little projects at a time, for example, I waited 4 years before attempting my biggest project yet. (Which is to build my local train in Roblox.) So, follow my advice to start slow and little. Don’t just rush to big projects when you aren’t ready yet.

For those wondering the reason it isn’t working is cause your variables reference game.startergui which is the severs reference to gui the clients reference would be script.Parent

If I am not wrong here, he needs to do this:
local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui

local getGuiEntry = script.Parent.UIhere.

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