Problem with SurfaceGui

Hello!

I am trying to make a part that has a SurfaceGui, which has a TextButton on it. The part is located in ReplicatedStorage and will be cloned to the workspace, so I try using .Activated with the TextButton but it doesn’t seem to work. (I run the code from StarterGui using a local script.). So after that, I tried putting SurfaceGui into the StarterGui and use Adornee to stick it to the part, but when cloned the Gui no longer stick to the part when cloned. (The ZIndex of the text buttons are also the highest in SurfaceGui). How do I fix this?

image

Can you show us the code please? @AlphazxParticles

1 Like
local Part1 = game.ReplicatedStorage:WaitForChild("Folder").Part1.SurfaceGui

Part1.MainBoard.ButtonList.Frame.TextButton.Activated:Connect(function()

print("Hi")

end)
Part1.MainBoard.ButtonList.Frame.TextButton.Activated:Connect(function()

print("Hi")

end)
Part1.MainBoard.ButtonList.Frame.TextButton.Activated:Connect(function()

print("Hi")

end)
Part1.MainBoard.ButtonList.Frame.TextButton.Activated:Connect(function()

print("Hi")

end)

local Cloned = Part1:Clone()
Cloned.Parent = game.Workspace

This is the current one.

Okey so first thing first, if you have multiple textbutton at the same level, i suggest you to rename them all.

1 Like

then second, i would suggest you to use a variable for this part:

Something like:

like that, you can do:

1 Like
local Part1 = game.ReplicatedStorage:WaitForChild("Folder").Part1.SurfaceGui

local frame = Part1.MainBoard.ButtonList.Frame

frame.TextButton1.Activated:Connect(function()

print("Hi")

end)

frame.TextButton2.Activated:Connect(function()

print("Hi")

end)

frame.TextButton3.Activated:Connect(function()

print("Hi")

end)

frame.TextButton4.Activated:Connect(function()

print("Hi")

end)

local Cloned = game.ReplicatedStorage:WaitForChild("Folder").Part1:Clone()

Cloned.Parent = game.Workspace

I changed it to this but it still doesn’t work.

change .Activated with .MouseButton1Click and it should work

Sadly, it still doesn’t work. Maybe the problem might be about the :Clone()?

What about this code? i rewrote it

wait hold on i made a mistake, give me a min

Here we go, i changed it, does it work? also i would suggest you to add a script as a child to every text button like TextButton.script and add the button code into it

1 Like

You are connecting a function to the same event 4 times. You should rename the text buttons before cloning them into the frame.

local Part1 = game.ReplicatedStorage:WaitForChild(“Folder”).Part1.SurfaceGui
local Cloned = Part1:Clone()
Cloned.Parent = game.Workspace --PARENT IT TO A PART

local frame = Cloned.MainBoard.ButtonList.Frame

frame.TextButton1.MouseButton1Click:Connect(function()

print(“Hi”)

end)
frame.TextButton2.MouseButton1Click:Connect(function()

print(“Hi”)

end)
frame.TextButton3.MouseButton1Click:Connect(function()

print(“Hi”)

end)
frame.TextButton4.MouseButton1Click:Connect(function()

print(“Hi”)

end)

as i said, yeah. Thanks to suggesting something already suggested

A few Syntax errors, but I’ve fixed them and it’s working now, thank you for the help!

you’re welcome, glad to hear it :+1:

1 Like