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

'MoneyGui' is nil when searching through PlayerGui?

Alright, so I'm making an FE enabled game and I have a gui called MoneyGui. This gui is inside of the StarterGui. When a remoteevent is fired it basically checks to see if moneygui is nil. This is the script:

local RS        = game:GetService("ReplicatedStorage")
local SSS       = game:GetService("ServerScriptService")
local RES       = RS["Remote Events"]
local RFS       = RS["Remote Functions"]
local EXT       = RS["Modules"]
local moneyRE   = RES:WaitForChild("Money")


moneyRE.OnServerEvent:connect(function(plr, request)
	if request == "updateMoneyGui" then
		print("update Request")
		for random,emh in pairs(plr.PlayerGui:GetChildren()) do
			print(emh.Name) -- When this whole loop is finished nothing gets printed. It's as if MoneyGui doesn't exist although I know it's inside of the PlayerGui.
		end
		if plr.PlayerGui:FindFirstChild("MoneyGui") ~= nil then
			print("It exists.")
		else
			print("It doesn't exist.")
		end
		
	end
end

It's a really simple script. The output has 'update Request' printed, although after that nothing is printed even though MoneyGui is in the player gui. It also prints 'It doesn't exist.' because it doesn't find the moneygui.

Now, I tested to see if this would work with FE off. I turned off FE and it worked perfectly. This is really strange, and I've never encountered this before. I think that I can't access the PlayerGui with FE on.

Please help!

1 comment

0

Where is the script? And what kind of script is it?

1 answer

✓ Accepted answer

I rewrote the code for you a bit, keep in mind this lays on if the fired event is a string. Which I made it in this case.

local RS        = game:GetService("ReplicatedStorage")
local SSS       = game:GetService("ServerScriptService")
local RES       = RS["Remote Events"]
local RFS       = RS["Remote Functions"]
local EXT       = RS["Modules"]
local moneyRE   = RES:WaitForChild("Money")


moneyRE.OnServerEvent:connect(function(plrname, request) --you could try to replace OnServerEvent with OnClientEvent, incase the server fires.
    if request == "updateMoneyGui" then
        print("update Request")
        for random,emh in pairs(game.Players[plrname].PlayerGui:GetChildren()) do
            print(emh.Name)
        end
        if game.Players[plrname].PlayerGui:FindFirstChild("MoneyGui") ~= nil then
            print("It exists.")
        else
            print("It doesn't exist.")
        end

    end
end

Again, make sure to check if your fired event is a string or an object.

1 comment

0

Thanks for the help! Although, it turns out that with FE enabled you can't actually access the PlayerGui from a server script like this. Your answer seems to be efficient though, so I'll accept it :)

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