Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempt to a nil value while accessing PlayerGui?

Asked by 5 years ago
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?

0
is this a regular script? DeceptiveCaster 3761 — 5y
0
yes S_H1234 7 — 5y
0
then what do i have to use? S_H1234 7 — 5y
0
You should try using a RemoteEvent. Hellnickell 5 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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)
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 SerpentineKing 3885 — 5y
0
what the contents of startergui are cloned locally User#24403 69 — 5y
Ad

Answer this question