Convert button to a gui button

So I have this tesla gate model for my SCP game and I want to make a gui button turn the tesla gate on and off instead of a physical button, heres the script (credit to “xImmortalChaos”):

local Mode = 1

local Button = script.Parent.Button.Button
local OnlineLight = script.Parent.Online
local OfflineLight = script.Parent.Offline
local Electricity = script.Parent.Electricity
local Detector = script.Parent.Detector
local Main = script.Parent

local Debounce = false

Button.ClickDetector.MouseClick:connect(function(Player)
	if Debounce then return end
	Debounce = true
	if Mode == 1 then
		Electricity.ComingOnline:Play()
		wait(0.5)
		Electricity.Humming:Play()
		Mode = 2
	elseif Mode == 2 then
		Electricity.GoingOffline:Play()
		wait(0.85)
		Electricity.Humming:Stop()
		Mode = 1
	end
	wait(0.4)
	Debounce = false
end)

Spawn(function()
	while wait(0.2) do
		if Mode == 1 then
			OnlineLight.Transparency = 1
			if OfflineLight.Transparency == 0.5 then
				OfflineLight.Transparency = 0
			else
				OfflineLight.Transparency = 0.5
			end
		elseif Mode == 2 then
			OfflineLight.Transparency = 1
			if OnlineLight.Transparency == 0.5 then
				OnlineLight.Transparency = 0
			else
				OnlineLight.Transparency = 0.5
			end
		end
	end
end)

Spawn(function()
	while wait() do
		for _,Player in pairs(game.Players:GetPlayers()) do
			if Player.Character and Player.Character:FindFirstChild("Torso") then
				if (Player.Character.Torso.Position - Detector.Position).Magnitude <= 7 then
					if Mode == 2 then
						Electricity.Humming.Volume = 1
						Electricity.Power:Play()
						wait(0.5)
						Electricity.Zap:Play()
						if Player.Character and Player.Character:FindFirstChild("Torso") then
							if (Player.Character.Torso.Position - Detector.Position).Magnitude <= 7 then
								Player.Character.Humanoid.Health = 0
							end
						end
						Main.Left.Material = "Neon"
						Main.Right.Material = "Neon"
						Electricity.Decal1a.Transparency = 0
						Electricity.Decal1b.Transparency = 0
						wait(0.01)
						Electricity.Decal1a.Transparency = 1
						Electricity.Decal1b.Transparency = 1
						Electricity.Decal2a.Transparency = 0
						Electricity.Decal2b.Transparency = 0
						wait(0.01)
						Electricity.Decal1a.Transparency = 1
						Electricity.Decal1b.Transparency = 1
						Electricity.Decal2a.Transparency = 1
						Electricity.Decal2b.Transparency = 1
						wait(0.01)
						Electricity.Decal1a.Transparency = 0
						Electricity.Decal1b.Transparency = 0
						wait(0.01)
						Electricity.Decal1a.Transparency = 1
						Electricity.Decal1b.Transparency = 1
						Electricity.Decal2a.Transparency = 0
						Electricity.Decal2b.Transparency = 0
						wait(0.01)
						Electricity.Decal1a.Transparency = 1
						Electricity.Decal1b.Transparency = 1
						Electricity.Decal2a.Transparency = 1
						Electricity.Decal2b.Transparency = 1
						wait(0.01)
						Electricity.Decal1a.Transparency = 0
						Electricity.Decal1b.Transparency = 0
						wait(0.01)
						Electricity.Decal1a.Transparency = 1
						Electricity.Decal1b.Transparency = 1
						Electricity.Decal2a.Transparency = 0
						Electricity.Decal2b.Transparency = 0
						wait(0.01)
						Electricity.Decal1a.Transparency = 1
						Electricity.Decal1b.Transparency = 1
						Electricity.Decal2a.Transparency = 1
						Electricity.Decal2b.Transparency = 1
						wait(0.01)
						Electricity.Decal1a.Transparency = 0
						Electricity.Decal1b.Transparency = 0
						wait(0.01)
						Electricity.Decal1a.Transparency = 1
						Electricity.Decal1b.Transparency = 1
						Electricity.Decal2a.Transparency = 0
						Electricity.Decal2b.Transparency = 0
						wait(0.01)
						Electricity.Decal1a.Transparency = 1
						Electricity.Decal1b.Transparency = 1
						Electricity.Decal2a.Transparency = 1
						Electricity.Decal2b.Transparency = 1
						wait(0.01)
						Electricity.Decal1a.Transparency = 0
						Electricity.Decal1b.Transparency = 0
						wait(0.01)
						Electricity.Decal1a.Transparency = 1
						Electricity.Decal1b.Transparency = 1
						Electricity.Decal2a.Transparency = 0
						Electricity.Decal2b.Transparency = 0
						wait(0.01)
						Electricity.Decal1a.Transparency = 1
						Electricity.Decal1b.Transparency = 1
						Electricity.Decal2a.Transparency = 1
						Electricity.Decal2b.Transparency = 1
						Main.Left.Material = "Metal"
						Main.Right.Material = "Metal"
						wait(.5)
						for i,v in pairs(Electricity:GetChildren()) do
							if v:IsA("Decal") then
								v.Transparency = 1
							end
						end
						Electricity.Humming.Volume = 0.5
					end
				end
			end
		end
	end
end)
4 Likes

Do you mean a billboard gui? That seems like what you want

2 Likes

Like just a textbutton, its going to be in an admin gui

Okay, I think I understand now, this is what you want: SurfaceGui | Documentation - Roblox Creator Hub read this page it should have what you want.

2 Likes

I don’t mean it to be a button on the model, I mean for it to be a ScreenGui in StarterGui for admins only

Its billboard gui then if you want the one that seems like its floating

1 Like

It’s just a ScreenGui in StarterGui, its not connected to the model, heres the path:

game.StarterGui.ScreenGui.Button

No. Do not use StarterGui.

Use game.Players.Localplayer.PlayerGui.ScreenGui.Button.

Use a playeradded event to use this

1 Like

Player added is a server thing and im sure the server doesn’t know what a local player is

1 Like

game.Players.PlayerAdded:Connect(function(localplayer)
yes you can get the localplayer

1 Like

Regardless, how would you make the button a StarterGui button? I have tried multiple ways but none have worked

Not to be argumentative but i dont think you understand the difference

1 Like
game.Players.PlayerAdded:Connect(function(plr)
	plr.PlayerGui
end)

yeah you can get the localplayer. PlayerGui is cloned from StarterGui and stored in the localplayer

this is a serverscript

1 Like

Local player is for local scripts, the player that gets returned by the player class is a player object.

Using local player as a variable name in server scripts is confusing to beginner’s so i would recommend to refrain from addressing it like that

2 Likes