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

My GUi Script is failing and I don't know what it's talking about, keep getting nil error?

When I try to open my book here is what it says and here is my script, and I'm getting frustrated!

local book = game:GetService('Workspace').Table.Book.ClickDetector
local close = PlayerGui.Book.Close
local next1 = PlayerGui.Book.Next1
local back1 = PlayerGui.Book.Back1

book.MouseClick:Connect(function()
	PlayerGui.Book.Enabled = true
end)


close.MouseButton1Click:Connect(function()
	PlayerGui.Book.Enabled = false
end)

next1.MouseButton1Click:Connect(function()
	PlayerGui.Book.Close.Visible = false
	PlayerGui.Book.Close.Selectable = false
	PlayerGui.Book.Blood.Visible = false
	PlayerGui.Book.Pyro.Visible = false
	PlayerGui.Book.Pain.Visible = true
	back1.Visible = true
	back1.Selectable = true
	next1.Visible = false
	next1.Selectable = false

The error says 'Players.JaytheKing452.PlayerGui.Book.BookScript:8: attempt to index global 'PlayerGui' (a nil value)'

1 answer

✓ Accepted answer

Ahh I see the problem, you are forgetting to reference the local player. Each player has their own Screen GUI, which means the local player has to be referenced before accessing the PlayerGui. It would go something like this!

local plr = game:GetService('Players').LocalPlayer
local book = game:GetService('Workspace').Table.Book.ClickDetector
local close = plr.PlayerGui.Book.Close
local next1 = plr.PlayerGui.Book.Next1
local back1 = plr.PlayerGui.Book.Back1

book.MouseClick:Connect(function()
	plr.PlayerGui.Book.Enabled = true
end)


close.MouseButton1Click:Connect(function()
	plr.PlayerGui.Book.Enabled = false
end)

next1.MouseButton1Click:Connect(function()
	plr.PlayerGui.Book.Close.Visible = false
	plr.PlayerGui.Book.Close.Selectable = false
	plr.PlayerGui.Book.Blood.Visible = false
	plr.PlayerGui.Book.Pyro.Visible = false
	plr.PlayerGui.Book.Pain.Visible = true
	back1.Visible = true
	back1.Selectable = true
	next1.Visible = false
	next1.Selectable = false

Do you see how I am referencing the local player before gui, just remember that!

2 comments

0

ill test it ourt right now

0

Works THANKS!

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