Cannot add a GUI to the playerGui folder from a server script

I removed it and it still doesn’t work. That wasn’t affecting it before though, because I said I did print debugging and all the prints printed to the console correctly.

I’ve done that, however I still need to fix the issue of it not creating the guis. It works fine when you spawn in for the first time, but after that it does not work.

Could you show the code after you’ve rewritten it?

for i, player in pairs(players) do
	if player then
		local character = player.Character or player.CharacterAdded:Wait()
		local humanoid = character:WaitForChild("Humanoid")
		local newGUI
		resetGUIConnection = player.CharacterAdded:Connect(function()
			for i, tile in pairs(tiles) do
				newGUI = sGUI:Clone()
				newGUI.Parent = workspace
				newGUI.Adornee = tile
			end
		end)
	end
end

Are you sure the GUI isn’t being added, or is it just not showing up? Check workspace and see if it’s being cloned into it.

I did and nothing was added to it.

Ok so I changed something, and now it adds to the workspace, but still doesn’t add itself to the player gui when I change workspace to the gui folder. Is this something to do with FE?

newGui.Parent = player.PlayerGui should work?

Also could you show the code after the change you made that fixed the parenting?

for i, player in pairs(players) do
	if player then
		local newGUI
		resetGUIConnection = player.CharacterAdded:Connect(function()
			for _, tile in pairs(tiles) do
				newGUI = sGUI:Clone()
				newGUI.Parent = player.PlayerGui:WaitForChild("TileEffectFolder")
				newGUI.Adornee = tile
			end
		end)
	end
end

Are you getting any errors or warnings? Does the TileEffectFolder exist in that location for the server too?

something you should reconsider is the gui being a SurfaceGui. SurfaceGuis usally dont need extra coding to make sure it doesn’t disappear if the player respawns cause it can only be applied to a part. your script might work for a ScreenGui, but a ScreenGui works as a gui shown on the player’s screen. because of this, you might not need the script at all. you can test if it is still there if you respawn by disabling the script in the script’s properties.

It’s added to the player, and when the player respawns they reset.

No errors or warnings as mentioned in the original post. TileEffectFolder is in the right place as confirmed with a print statement

When the parent is the workspace, it adds them to it. When I set the parent to the player gui folder it doesnt add it

I did some more testing and found out I can add the surface guis to the player, but I cannot add them to the player gui folder. Any idea on why this is happening?

Regarding your old problem ,as some other stated, you should be connecting to game.Players:PlayerAdded()

That should not be the case, but ScreenGui is only visible in StarterGui/PlayerGui and SurfaceGui is only visible on the surface of a part. You should be able to parent SurfaceGui to PlayerGui though, but it won’t be visible.

I’ve tested it and I’m not sure what your point is here.

Read farther up and you can see where this is just a small part of a larger piece of code fired from an event. If I’m firing off of an event, then the players added function won’t run because the players would have already ran.

Also for some reason it isn’t adding to player GUI. I’ve tested it, and the first time around it does show up in the playergui, however on respawn it no longer shows up. The problem is somewhere in this code. It will add to the player but not playergui. In my testing, the functions I gave the screen GUI do not run, and if I add a decal to it, it does not show. I believe this might be something to do with filtering enabled.

What you implied in your previous post was surfaceguis can’t be added to playergui, but anyways, not sure if you read what people said but the reason it’s not working is because you need to connect to game.Players:PlayerAdded() to get player. You’re also doing resetGUI2:Disconnect() which means once they die, the even will never fire again. You shouldn’t be disconnecting here.

Humanoid have nothing to do with this

Look at my most recent post of my code. Also this is part of an event. PlayerAdded would never fire because the player is already added and thus wouldn’t be added again. I’m sending the player through an argument in the event.
I mentioned both of these things in a post above.

What I believe is the only problem is that no matter what I clone, it can be a descendant of anything except playergui. For some reason I can add a surface gui to the player, but not the playergui folder.I’ve tested it with print statements and everything exists and is using the correct path to reach it.

The bug is something to do with adding an instance to the playergui folder seeing as I’m able to add it to the player but not the playergui folder on their respawn. I’ve been able to add it to them in a different server script, so I don’t quite know what the issue is here.

for _, player in pairs(players) do
	if player then
		resetGUIConnection = player.CharacterAdded:Connect(function()
			for i, tile in pairs(tiles) do
				local newGUI = sGUI:Clone()
				newGUI.Parent = player:WaitForChild("PlayerGui"):WaitForChild("TileEffectFolder")
				newGUI.Adornee = tile
			end
		end)
	end
end

I found the solution.

With filtering enabled, I couldn’t access the player’s GUI folder from the server side.

Thank you for the help in pointing out other issues I had with my code.

Sources:

1 Like