How to make a new text button appear with different text when you click a text button?

  1. What do you want to achieve?
    Make a FNaF fangame.
  2. What is the issue?
    I am trying to make so when you press a text button a new one appears saying “Camera” instead of “Back” (it got destroyed when I clicked it) and when I click “Camera” text button, the image button and other text buttons appear again, but “Camera” text button gets destroyed and “Back” one appears again, so basically a loop.
    Here is my script:

local Camera = game.StarterGui.ScreenGui.BackButton
local Clone = Camera:Clone()

if Camera then
wait(0.1)
game.StarterGui.ScreenGui.BackButton:Destroy()
Clone:Clone().Parent = game.StarterGui.ScreenGui.BackButton.LocalScript
Clone:Clone().Parent.Name = “CameraButton”
Button.MouseButton1Click:Connect(function()
ImageButton.Visible = true
end)
end

  1. What solutions have you tried so far?
    Now, because barely anyone makes FNaF games on roblox (not the RP ones),
    there are no posts helping me.

Well you did a mistake everything you wrote could have ran so on to the mistake:
StarterGui is replicated or placed in PlayerGui when game starts so that’s not gonna work out sadly

You should use PlayerGui instead add this to 1st line:

local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")

And replace game.StarterGui with PlayerGui

Hello, is this what you meant?

image

Why are you destroying the back button? No need to do that. Just change its visibility. You can easily make a new button appear by manipulating the items visibility.

TextButton.Visible = true

local Camera = game.PlayerGui.ScreenGui.CameraButton

local TextButton = game.PlayerGui.ScreenGui.BackButton

local ImageButton = game.PlayerGui.ScreenGui.ImageButton

local PlayerGui = game.Players.LocalPlayer:WaitForChild(“PlayerGui”)

if Camera then

wait(0.1)

TextButton.Visible = false

Camera.Visible = true

Camera.MouseButton1Click:Connect(function()

ImageButton.Visible = true

end)

end

I tweaked the script to this, but now the BackButton completly doesn’t become invisible and Camera becomes visible.

Because you are not making the camera invisible

For some reason, my BackButton doesn’t get destroyed/turn invisible.

Can you show your whole script you might have missed something

game.PlayerGui isn’t a thing and that would error.
You would have 2 events, one for the camera button, one for the text button, you would toggle them to visible/invisible, along with a function running.

local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player.PlayerGui

local TextButton = PlayerGui:WaitForChild("ScreenGui"):WaitForChild("TextButton")
local CamButton = PlayerGui.ScreenGui:WaitForChild("CameraButton")

function TextButtonActivated()
    CamButton.Visible = true
    TextButton.Visible = false
    --do stuff u want to do when the text button gets clicked
end
function CamButtonActivated()
    CamButton.Visible = false
    TextButton.Visible = true
    --Make the other buttons visible too
    --do stuff u want to do when the cam button gets clicked
end

TextButton.MouseButton1Click:Connect(TextButtonActivated)
CamButton.MouseButton1Click:Connect(CamButtonActivated)

The BackButton now is working, but the camera button isn’t getting visible.

Maybe it’s something to do with the placement of the script?

1 Like

local Player = game:GetService(“Players”).LocalPlayer
local PlayerGui = Player.PlayerGui

local TextButton = PlayerGui:WaitForChild(“ScreenGui”):WaitForChild(“BackButton”)
local CamButton = PlayerGui.ScreenGui:WaitForChild(“CameraButton”)
local MapGui = PlayerGui.ScreenGui:WaitForChild(“ImageButton”)

function TextButtonActivated()
CamButton.Visible = true
TextButton.Visible = false
MapGui.Visible = false
function CamButtonActivated()
CamButton.Visible = false
TextButton.Visible = true
MapGui.Visible = true

TextButton.MouseButton1Click:Connect(TextButtonActivated)
CamButton.MouseButton1Click:Connect(CamButtonActivated)
end
end

The script is local and is a child of ScreenGui.