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

Attempt to a nil value while accessing PlayerGui?

script.Parent.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		player:WaitForChild("PlayerGui"):FindFirstChild("Shop").Open.Value = true
	end
end)

This script will make a boolvalue to true and another localscript will make a gui open if the boolvalue is true. But it attempted to a nil value. What does that mean?

4 comments

0

is this a regular script?

0

yes

0

then what do i have to use?

0

You should try using a RemoteEvent.

1 answer

I see from the comments that you are using a server script to change the GUI.

Due to filtering enabled, client objects will not get replicated to the server, if you want to access the player's gui, you would have to manually clone them to their PlayerGui when they join, then the server made this change and you can change it on the server as well.

I recommend that you, however, instead use a LocalScript on the client and use a RemoteEvent or RemoteFunction, and then fire those events from the server and tell the client to do something.

Check the example below, note that it is not to be used in a production game, it's just an example of how you would do this.

-- // Server code

local ReplicatedStorage = game:GetService("ReplicatedStorage");
local GUIToggler = ReplicatedStorage:WaitForChild("GUIToggler");

-- "PlayerHere" is the player instance
GUIToggler:FireClient(PlayerHere, "open");

-- // Client code

local ReplicatedStorage = game:GetService("ReplicatedStorage");
local GUIToggler = ReplicatedStorage:WaitForChild("GUIToggler");

GUIToggler.OnClientEvent:Connect( function (action)
	print("Request received from the server");
	if action == "open" then
		-- Open the gui
	else
		-- Close the gui
	end
end)

2 comments

0

well technically the gui items are visible on the server if they were initially in starter gui but cannot be read from or changed on the server. This is correct otherwise

0

what the contents of startergui are cloned locally

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