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

How do I fix a error for GUI "nil value" for a name?

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)

1 answer

✓ Accepted answer

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! :)

1 comment

0

Thank you soooo much!

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