"Attempt to index nil with PlayerGui"

Hi! In my ProximityPromt script, I can’t seem to index the PlayerGui.
What’s wrong?
Thanks!
(not the full script, it’s what this is being used for. the other stuff in unimportant towards this error.)

THIS IS A SERVER SCRIPT

workspace.feedbacknPC.Torso.ProximityPrompt.Triggered:Connect(function(player)
	local ui = plr.PlayerGui:WaitForChild("Feedback", 15)
	ui.MainFrame:TweenPosition(UDim2.new(0.344, 0, 0.673, 0), "Out", "Quart", .5, true) --0.673
end)

Full script (just my proximityprompt things)



wait(5)

workspace.City.Cafe.Cafe.Sink1.ProxPart.ProximityPrompt.ActionText = "Turn On Fossit"
workspace.City.Cafe.Cafe.Sink2.ProxPart.ProximityPrompt.ActionText = "Turn On Fossit"
wait()
workspace.City.Cafe.Cafe.Sink1.FossitPart.ParticleEmitter.Enabled = false
	workspace.City.Cafe.Cafe.Sink1.ProxPart.ProximityPrompt.Triggered:Connect(function(player)
		
	--- turn on
		if  workspace.City.Cafe.Cafe.Sink1.ProxPart.ProximityPrompt.ActionText == "Turn On Fossit" then
			wait()
	print("Someone has turned on the fossit.")
		workspace.City.Cafe.Cafe.Sink1.FossitPart.ParticleEmitter.Enabled = true
			workspace.City.Cafe.Cafe.Sink1.ProxPart.ProximityPrompt.ActionText = "Turn Off Fossit"
			wait()
		---turn off
		elseif  workspace.City.Cafe.Cafe.Sink1.ProxPart.ProximityPrompt.ActionText == "Turn Off Fossit" then
			wait()
			print("Someone has turned off the fossit.")
			workspace.City.Cafe.Cafe.Sink1.FossitPart.ParticleEmitter.Enabled = false
			workspace.City.Cafe.Cafe.Sink1.ProxPart.ProximityPrompt.ActionText = "Turn On Fossit"
			wait()
		end
	
end)
------------------------------------------SINK2--------------------------------------------------
	workspace.City.Cafe.Cafe.Sink2.FossitPart.ParticleEmitter.Enabled = false
	workspace.City.Cafe.Cafe.Sink2.ProxPart.ProximityPrompt.Triggered:Connect(function(player)
		--- turn on
		if  workspace.City.Cafe.Cafe.Sink2.ProxPart.ProximityPrompt.ActionText == "Turn On Fossit" then
			wait()
			print("Someone has turned on the fossit.")
			workspace.City.Cafe.Cafe.Sink2.FossitPart.ParticleEmitter.Enabled = true
			workspace.City.Cafe.Cafe.Sink2.ProxPart.ProximityPrompt.ActionText = "Turn Off Fossit"
			wait()
			---turn off
		elseif  workspace.City.Cafe.Cafe.Sink2.ProxPart.ProximityPrompt.ActionText == "Turn Off Fossit" then
			wait()
			print("Someone has turned off the fossit.")
			workspace.City.Cafe.Cafe.Sink2.FossitPart.ParticleEmitter.Enabled = false
			workspace.City.Cafe.Cafe.Sink2.ProxPart.ProximityPrompt.ActionText = "Turn On Fossit"
			wait()
		end

end)

workspace.City.Cafe.Cafe.Sink1.ProxPart.ProximityPrompt.Triggered:Connect(function(player)
	
end)
local plr = game.Players.LocalPlayer
workspace.e.ProximityPrompt.Triggered:Connect(function(player)
	for i = 1,1000 do
	plr = game.Players.LocalPlayer
		workspace.f.SurfaceGui.TextLabel.Text = ("returned true turns out you NOT STINKI")
		wait()
		if plr == nil then
			workspace.f.SurfaceGui.TextLabel.Text = ("lol returned nil noob bad scripting")
			break
		
		end
		end
end)

workspace.feedbacknPC.Torso.ProximityPrompt.Triggered:Connect(function(player)
	local ui = plr.PlayerGui:WaitForChild("Feedback", 15)
	ui.MainFrame:TweenPosition(UDim2.new(0.344, 0, 0.673, 0), "Out", "Quart", .5, true) --0.673
end)

Thanks for any help!

Wouldn’t it be

local ui = player.PlayerGui:WaitForChild("Feedback", 15)

As the it is “player” in the parameter, rather than “plr”?

1 Like
	plr = game.Players.LocalPlayer

If you looked in the full script, it was previously defined.

This is a server script though, you can’t index localPlayer in a Server script.

If this is all a ServerScript, then you cannot do local plr = game.Players.LocalPlayer. LocalPlayer can only be obtained from a LocalScript.

How can I index the PlayerGui then through the prox. prompt?

change into

workspace.feedbacknPC.Torso.ProximityPrompt.Triggered:Connect(function(player)
	local ui = player.PlayerGui:WaitForChild("Feedback", 15)
	ui.MainFrame:TweenPosition(UDim2.new(0.344, 0, 0.673, 0), "Out", "Quart", .5, true) --0.673
end)


the reason why is mentioned already

2 Likes

You can obtain the Player through the functions parameters. As I mentioned before, or you can look at what @hestolemyrice posted above.

I’m pretty sure you can’t access playergui in a server script, since that’s what many have told me. Try using remote events.

you can, you only can’t access player scripts

Interesting. Still, wouldn’t it make sense for the client to handle playergui instead of the server? The server should be where you do critical tasks, instead of using up server resources.

Edit: Here’s a post about it, actually.

Thanks, But now it only completes the tween once.
.

Take a close look at the position

You might need to change everything into a local script

but you cant find if a proximityprompt is triggered locally, it has to be server sided, right?

The reason why it only does once is most likely because the script only runs 1 time

workspace.feedbacknPC.Torso.ProximityPrompt.Triggered:Connect(function(player)
print("triggered")
	local ui = player.PlayerGui:WaitForChild("Feedback", 15)
	ui.MainFrame:TweenPosition(UDim2.new(0.344, 0, 0.673, 0), "Out", "Quart", .5, true) --0.673
end)

I need to see if it prints

You can detect if a proximityprompt fires on server or client or both

image

lemme see the video too like i need to see the output and you triggering it at the same time