Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Making a admin gui but i can't seem to get it the text in the command box right?

So two problems that I don't know how to address. Each of the buttons that are clicked will change the scrollingGui doesn't work. And when they type in the command bar and then press the "Execute" button it takes what they put then sees if it is one of the commands and if so execute it. But before that can happen it is not even fireing what they put in the command bar. I know I am probably using it wrong, but I am stuck.

local script

---Player thingy
local player = game.Players.LocalPlayer
repeat wait() until player.Character
local char = player.Character
local mouse = player:GetMouse()



---Services
local uis = game:GetService("UserInputService")




--- Guis
local screen = script.Parent
local Cmd = screen.CmdBox
local execute = screen.Run
local maingui = screen.Gui
local mainframe = maingui.Frame
local history = mainframe.ChatHistory
local list = mainframe.AdminList
local Cmds = mainframe.Commands
local history1 = mainframe.ChatHistory1
local list1 = mainframe.AdminList1
local Cmds1 = mainframe.Commands1
local expla = mainframe.Explanation


--Event
local event = screen:WaitForChild("Event")


uis.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.BackSlash then
		Cmd:CaptureFocus()
	end
end)

history1.MouseButton1Down:connect(function()
	print("Good")
	history.Visible = true and list.Visible == false and Cmds.Visible == false
	print("Sucess")
	
	
end)
list1.MouseButton1Down:connect(function()
	print("good2")
	list.Visible = true and history.Visible == false and Cmds.Visible == false
	print("Sucess2")
end)
Cmds1.MouseButton1Down:connect(function()
	print("good3")
 Cmds.Visible = true and list.Visible == false and history.Visible == false
print("Sucess3")
end)


execute.MouseButton1Down:connect(function()
	if Cmd.Text ~= nil then
		Cmd.Text:FireServer(Cmd.Text)
	
	
	
	
	
	
	end
end)




server script

---Player thingy
local player = script.Parent.Parent.Parent
repeat wait() until player.Character
local char = player.Character




---Services




--- Guis
local screen = script.Parent
local Cmd = screen.CmdBox
local execute = screen.Run
local maingui = screen.Gui
local mainframe = maingui.Frame
local history = mainframe.ChatHistory
local list = mainframe.AdminList
local Cmds = mainframe.Commands
local history1 = mainframe.ChatHistory1
local list1 = mainframe.AdminList1
local Cmds1 = mainframe.Commands1
local expla = mainframe.Explanation


--Event
local event = screen:WaitForChild("Event")

--- Admins
local admins = {["Player1"] = true, ["Player"] = true, ["yougottols1"] = true, ["Cyber_Monkey"] = true}




event.OnServerEvent:connect(function(plyr, Trying)
	print("Fired")
	
end)







2 answers

✓ Accepted answer

There are quite a lot of problems here that need to be looked at:-

  1. Both scripts should not be trying to get the player object as any changes need to be done on the server side (All checks should be done on the server even if you check them on the client side as well). The player object is passed as a parameter when the event is received on the server.

  2. Based upon the fact that you have local event = screen:WaitForChild("Event") this suggests that the event is inside the gui, this is not a good place to put the event as you would need to connect the event each time the gui is added from the server side as it is delete when the player dies. It is best to put this remote event into the ReplicatedStorage.

  3. Cmds.Visible = true and list.Visible == false and history.Visible == false the and operator is used to compare variable. You need to set the value not compare them e.g. == is a comparison and = is an assignment.

  4. As nicemike40 has mentioned you are not firing the event, you are trying to fire the text parameter??

Other points:-

It is not a good idea to use the players name as users can change them, use UserId as this cannot be changed and will allow users to change their name while still being an admin.

The fix (local script):-

---Player things
local mouse =  game.Players.LocalPlayer:GetMouse()

---Services
local uis = game:GetService("UserInputService")

--- Guis, you may want to add in WaitForChild as there may be a small delay when replicateing the gui to the client
local screen = script.Parent
local Cmd = screen.CmdBox
local execute = screen.Run
local maingui = screen.Gui
local mainframe = maingui.Frame
local history = mainframe.ChatHistory
local list = mainframe.AdminList
local Cmds = mainframe.Commands
local history1 = mainframe.ChatHistory1
local list1 = mainframe.AdminList1
local Cmds1 = mainframe.Commands1
local expla = mainframe.Explanation

--Event
local event = game:GetService('ReplicatedStorage'):WaitForChild('') -- add event name

uis.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.BackSlash then
        Cmd:CaptureFocus()
    end
end)

history1.MouseButton1Down:connect(function()
    history.Visible = true  -- we use assignments
	list.Visible = false 
	Cmds.Visible = false
end)

list1.MouseButton1Down:connect(function()
    list.Visible = true 
	history.Visible = false 
	Cmds.Visible = false
end)

Cmds1.MouseButton1Down:connect(function()
 	Cmds.Visible = true
	list.Visible = false 
 	history.Visible = false
end)

execute.MouseButton1Down:connect(function()
    if Cmd.Text ~= '' then -- we need to check for a blank/empty string
		event:FireServer(Cmd.Text)
    end
end)

Server Script ( in ServerScriptService):-

--Event
local event = game:GetService('ReplicatedStorage'):WaitForChild('') -- event name here

--- Admins
local admins = {["Player1"] = true, ["Player"] = true, ["yougottols1"] = true, ["Cyber_Monkey"] = true}

event.OnServerEvent:connect(function(plyr, Trying)
    print('Fired by', plr, 'data sent', Trying)
end)

Example not using player name:-

--Event
local event = game:GetService('ReplicatedStorage'):WaitForChild('') -- event name here

--- Admins
local admins = {[player id here]= true, [player id here] = true, [player id here] = true}

event.OnServerEvent:connect(function(plyr, Trying)
	if admins[plyr.UserId] then -- user is in the list
   	 	print('Fired by', plr, 'data sent', Trying)
	else
		print('not admin')
	end
end)

I hope this helps, please comment if you do not understand how / why this code works.

Line 61 in your local script is Cmd.Text:FireServer(Cmd.Text). Try changing that to event:FireServer(Cmd.Text) instead.

This discussion is preserved as it was. New answers, comments, and votes are closed.