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

Why can I not add stuff to the PlayerGui upon respawning?

I am having this weird issue: I can store a GUI from the ReplicatedStorage into the player's PlayerGui on Start Up, but I can't store any GUI when respawning? Is there something I am missing here as to why I can't do this?

I can't even put a folder into the playerGui upon respawning, why is that? Am I even able to add stuff to the PlayerGui upon respawning or is it not allowed?

And why is it that when I do the same but add it to the player Backpack, it works? Why does it not work specifically for PlayerGui?

Example, this works:

game.Players.PlayerAdded:Connect(function(player) 
	player.CharacterAppearanceLoaded:Connect(function(char)
	
		local item = Instance.new("Folder")
		item.Name = "Whatever"
		item.Parent = player:WaitForChild("Backpack")

But this doesn't:

game.Players.PlayerAdded:Connect(function(player) 
	player.CharacterAppearanceLoaded:Connect(function(char)
	
		local item = Instance.new("Folder")
		item.Name = "Whatever"
		item.Parent = player:WaitForChild("PlayerGui")

I don't understand this, why can't I just add to PlayerGui?

1 answer

✓ Accepted answer

The reason you can not add to the playergui is because the PlayerGui is client sided, you are trying to access it via server. Also here is a good guide to help you with the issue you are having

So create a localscript in game.StarterPlayer.StarterPlayerScripts

Code:


local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")


local item = Instance.new("Folder")
item.Name = "Whatever"
item.Parent = PlayerGui

Look up Remote Events to learn more below.

If you wish to do it via when a player respawns then it can get a little more complicating.

To do this you can do as follows

a Script in game.ServerScriptService


local RespawnEvent = Instance.new("RemoteEvent")
RespawnEvent.Name = "RespawnEvent"
RespawnEvent.Parent = game.ReplicatedStorage


game.Players.PlayerAdded:Connect(function(Player)

	Player.CharacterAdded:Connect(function(Character)

		local Humanoid = Character:FindFirstChild("Humanoid")

		if Humanoid then
			Humanoid.Died:Connect(function() 
RespawnEvent:FireClient(Player) 
			end)
		end

	end)

end)

In a localscript in game.StarterPlayer.StarterPlayerScripts



local RespawnEvent = game.ReplicatedStorage:WaitForChild("RespawnEvent")

RespawnEvent.OnClientEvent:Connect(function(Player) 
	
	local PlayerGui = Player:WaitForChild("PlayerGui")
	local item = Instance.new("Folder")

	item.Name = "Whatever"
	item.Parent = PlayerGui

end)


1 comment

0

Thank you. I figured I had to use RemoteEvents for this. I had a weird workaround before but now it's causing this issue. I knew I'd eventually have to use RemoteEvents. Thank you. At least now I know what the issue is, before I had no idea.

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