Help with SurfaceGui

Hi! I have 2 SurfaceGuis in StarterGui, so these will be in playergui. When I want to create a button on the surfacegui via a button, it will appear on both surfaceguis while a specific surfacegui is designated in the script itself, in this case “DonateBoard2”. And yet when I create a button it will appear on both boards “DonateBoard1” and “DonateBoard2”. The intention is that when the owner of the stall clicks on the button, the button will be visible to every player in the SurfaceGui. When I put the SurfaceGui in the part itself I don’t get a player so a prompt purchase is not possible, via startergui it is.

Screen of the SurfaceGuis:
image

SurfaceGuis will appear on the white parts. (Left stall is stall two, tight stall is stall one)

Script

local EventFolder = game.ReplicatedStorage.Stall
local Button = script.Parent.ScrollingFrame.Donation

EventFolder.SendButton.OnServerEvent:Connect(function(plr, id, price, username)
	if game.Workspace:FindFirstChild("Stall"..username) then
		local a = Button:Clone()
		a.Parent = script.Parent.ScrollingFrame
		a.Visible = true
		a.Asset.Value = id
		a.Price.Value = price
		a.Text = price.." R$"
		a.Name = id
		a.Handler.Enabled = true
		a.Stats.Enabled = true
	end
end)

EventFolder.DeleteButton.OnServerEvent:Connect(function(plr, id)
	if Button.Parent:FindFirstChild(id) then
		Button.Parent:FindFirstChild(id):Destroy()
	else
		return
	end
end)
1 Like

I’m sorry but I can not understand the problem the you are facing.
Could you rephrase it or explain it to me, please?

I’m not sure if I get this correctly, you said that you wanted to, for example, to add a button to DonateBoard2 but the script adds a button for both DonateBoard1 and DonateBoard2?
Also assuming that your script is being parented inside both DonateBoard1 and DonateBoard2…

If that’s the case then:

  • Make sure that both of the DonateBoard 1 and 2 don’t share the same RemoteEvent.
  • If the RemoteEvent is shared then you have to add a check for which board you want to modify kinda like this:
 EventFolder.SendButton:Connect(function(plr, id, price, username, board)
	local stall = workspace:FindFirstChild("Stall"..username)
	if stall and board == script.Parent.Name then
		-- Rest of the code here

The same applies to the DeleteButton function:

EventFolder.DeleteButton.OnServerEvent:Connect(function(plr, id, board)
	if board == script.Parent.Name then
		-- Rest of the code here

The argument passed through board must be a string that is the name of the board for the code to run.

2 Likes

Hey! Sorry for the late reply and the confusion. You were absolutely right, I used the same events for both boards, now made them seperate and it works. Thanks!

1 Like

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