I was helping @nosensehemor (@NonsenseYt2) and then the issue happened…
If you read the title, this is what is says.
Video:
LocalScript:
script.Parent["Menu (Frame)"].Play.MouseButton1Click:Connect(function()
script.Parent.Enabled = false
end)
script.Parent["Menu (Frame)"].Quit.MouseButton1Click:Connect(function()
game.Players.LocalPlayer:Kick("Rejoin the game. If you do not want to play the game for a bit, join later !")
end)
if script.Parent.Enabled == true then
game.Players.LocalPlayer.PlayerGui.MainGui.Enabled = false
game.Players.LocalPlayer.PlayerGui.Warning.Enabled = false
game.Players.LocalPlayer.PlayerGui.RandomName.Enabled = false
elseif script.Parent.Enabled == false then
game.Players.LocalPlayer.PlayerGui.MainGui.Enabled = true
game.Players.LocalPlayer.PlayerGui.Warning.Enabled = true
game.Players.LocalPlayer.PlayerGui.RandomName.Enabled = true
end
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
repeat task.wait() until LocalPlayer:FindFirstChild("PlayerGui")
local PlayerGui = LocalPlayer.PlayerGui
local Gui = script.Parent
Gui["Menu (Frame)"].Play.MouseButton1Click:Connect(function()
Gui.Enabled = false
end)
Gui["Menu (Frame)"].Quit.MouseButton1Click:Connect(function()
LocalPlayer:Kick("Rejoin the game. If you do not want to play the game for a bit, join later !")
end)
if script.Parent.Enabled then
PlayerGui.MainGui.Enabled = false
PlayerGui.Warning.Enabled = false
PlayerGui.RandomName.Enabled = false
else
PlayerGui.MainGui.Enabled = true
PlayerGui.Warning.Enabled = true
PlayerGui.RandomName.Enabled = true
end
Most likely the local script is being run before the guis are fully added to the PlayerGui. I would just add :WaitForChild() calls for the guis you are trying to index.
I would NOT recommend using the solution above, as repeat task.wait() is usually one of the strategies devs try to avoid when coding because it can be inefficient and inconsistent. Also, in this case the use of it doesn’t even make sense since PlayerGui always exist under players. Not sure how that even fixed the issue tbh
This is the code that add the :WaitForChild() calls.
script.Parent["Menu (Frame)"].Play.MouseButton1Click:Connect(function()
script.Parent.Enabled = false
end)
script.Parent["Menu (Frame)"].Quit.MouseButton1Click:Connect(function()
game.Players.LocalPlayer:Kick("Rejoin the game. If you do not want to play the game for a bit, join later !")
end)
if script.Parent.Enabled == true then
game.Players.LocalPlayer.PlayerGui:WaitForChild("MainGui").Enabled = false
game.Players.LocalPlayer.PlayerGui:WaitForChild("Warning").Enabled = false
game.Players.LocalPlayer.PlayerGui:WaitForChild("RandomName").Enabled = false
elseif script.Parent.Enabled == false then
game.Players.LocalPlayer.PlayerGui:WaitForChild("MainGui").Enabled = true
game.Players.LocalPlayer.PlayerGui:WaitForChild("Warning").Enabled = true
game.Players.LocalPlayer.PlayerGui:WaitForChild("RandomName").Enabled = true
end
I usually don’t post on solved items unless I think the solution is flawed. So, am I sure? To the best of my knowledge. I’ve been programming in Roblox for a long time. If my solution works, I would recommend using it instead.