How to refresh Character without resetting gui?

I am trying to create an admin command that makes the player’s character be refreshed. I already made it so that if you use the command you reset without going back to spawn but I also have a problem where the spawn gui also resets when using the command. What should I do to avoid resetting the gui?

Here is the code that I’m using:

commands.refresh = function(sender, arguments)
	
	print(sender.Name.." used the refresh command.")
	
	local player = arguments[1]
	
	if player then
		
		local plyr = FindPlayer(player,sender)
		
		if plyr then
			
			local cframe = plyr.Character.HumanoidRootPart.CFrame
			plyr:LoadCharacter()
			plyr.Character.HumanoidRootPart.CFrame = cframe
			print(sender.Name.." refreshed "..plyr.Name.."'s character.")
			
		end
		
	else
		
		local cframe = sender.Character.HumanoidRootPart.CFrame
		sender:LoadCharacter()
		sender.Character.HumanoidRootPart.CFrame = cframe
		print(sender.Name.." refreshed "..sender.Name.."'s character.")
		
	end
	
end

Here is the spawn gui:

Did you get any errors when running the game?

I didn’t get any errors, it does reset the character but the spawn gui appears whenever the character is reset

There is a useful property of StarterGui which will not reset GUIs on respawn.

A tip, you can make this command have a cooldown by using debounce. While in the cooldown, you can set the PlayerGui that you are using and make the Enabled property disabled after finishing (like welcome gui after finishing it).

I am aware of that property but I do need the spawn gui to reset when the player dies so that they can choose where they spawn next to avoid them being spawn camped, but when using the command the gui won’t reset because the character will be put back to the same location.

Either toggle the property in the gui ResetOnSpawn to false or clone the gui before you reset the player then reparent it to the player after they are respawned/refreshed.

1 Like

The CharacterAdded event runs whenever a character respawns. You can use that.

Nevermind I fixed the problem, I just needed to delete the gui when you use the command. sorry for wasting your time.

1 Like