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

Some players PlayerGui disappears randomly due to this warning?

I want players to get their GUI from the ServerStorage, and when a player dies their GUI will be destroyed. However, one of the players do not receive the GUI for the game.

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
	--wait() --I tried adding a wait() in this line, but it doesn't work.
	game:GetService("Players").LocalPlayer.PlayerGui.Sprinter:Destroy() --I believe this line shows the warning.
end)

Something unexpectly tried to set the parent of Sprinter to NULL while trying to set the parent of Sprinter. Current parent is PlayerGui.

Any comments on how to solve this issue? I tried adding wait() or spawn(function(), but it didn't work.

2 answers

As default behaviour, player gui is being destroyed and regenerated every time character respawns. Problem is you are trying to destroy GUI at the same time. To switch off this functionality and preserve gui when player dies, you need to uncheck "ResetOnSpawn" in "Sprinter" properties. Beware: Sprinter will not be re-created until player quits and rejoins your game. If you want it back, instead of destroying, i suggest to set the Enabled property to false, and later back to true when needed.

1 comment

0

That could work but other players can still have the GUI working, even if it's enabled to false.

on a client even you need to send information to the local script about who activated the event so instead of putting

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()

fill in inside of the function() who activated it, or with other words the string you fired from the server script, then on the second line you can use that player to destroy the gui, so here is an example of what i mean if in the server script u do for example

local player = game.Players:GetPlayerFromCharacter(hit.Parent)
game.ReplicatedStorage.RemoteEvent:FireClient(player)

then in the local script you can do

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(player)
  player.PlayerGui.Sprinter:Destroy() 
end)

you can use that player.PlayerGui since you have what player fired the event in the function()

2 comments

1

I assume that the client is capable of finding their own player.

0

this is a faster way anyway instead of doing game.Players.LocalPlayer twice

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