So, I'm trying to make a GUI appear for one player. I had an idea to go into the player folder under explorer, find the players name who clicked the GUI, and open the GUI for them. I keep on getting a error. Any help?
local name = plr.Character.Name Button2.MouseButton1Down:connect(function() game.Players.name.PlayerGui.TrailGUI.Main.Visible = true end)
Error: Workspace.TrailGUI:151: attempt to index field 'Character' (a nil value)
Perhaps the character hasn't loaded yet at runtime. You want to yield to make sure that the character exists before proceeding using CharacterAdded:Wait()
. Also, what you've done on line 3 won't work because saying game.Players.name
will look for a name
property of game.Players
, it won't look for the value of name.
Here's what you can do instead:
local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local playerGui = player:WaitForChild("PlayerGui") local trailGui = playerGui:WaitForChild("TrailGUI") local main = trailGui:WaitForChild("Main") Button2.MouseButton1Down:Connect(function() -- changed connect to Connect because connect is deprecated main.Visible = true end)
Hope this helps! :)