08:18:12.704 - Players.Player1.PlayerGui.main_Panel.admingui.warn.LocalScript:2: attempt to call method 'FindFirstChild' (a nil value) 08:18:12.704 - Stack Begin
Here is the code:
local player = game.Players:GetPlayers() local gui = player:FindFirstChild("PlayerGui"):FindFirstChild("main_Panel") local warnbutton = gui:FindFirstChild("admingui"):FindFirstChild("warn") local typemessage = gui:FindFirstChild("admingui"):FindFirstChild("typemessage") local warnmessage = gui:FindFirstChild("admingui"):FindFirstChild("warnmessage") warnbutton.MouseButton1Click:connect(function() print("bruh") end)
Ok lets start out by making sure we are doing this is a localscript, after that lets set up our player variable
local player = game.Players.LocalPlayer
After that we will set up our gui variables
local gui = player.PlayerGui:WaitForChild("main_Panel")--waitforchild so we make sure its there local warnbutton = gui:WaitForChild("admingui").warn
Now for our messages
local typemessage = gui:WaitForChild("admingui").typemessage local warnmessage = gui.warnmessage
Finally our event
warnbutton.MouseButton1Click:connect(function() print("bruh") end)
Lets put it together,
local player = game.Players.LocalPlayer local gui = player.PlayerGui:WaitForChild("main_Panel") local warnbutton = gui:WaitForChild("admingui").warn local typemessage = gui:WaitForChild("admingui").typemessage local warnmessage = gui.warnmessage warnbutton.MouseButton1Click:connect(function() print("bruh") end)
In conclusion to get to the player you get the LocalPlayer from players, only works in localscript. Also you don't need to use findfirstchild for everything and unique named instances