Gui not working with clicked?

im making something where when you click a textbutton will revert you back to your old avatar after transforming but for some reason its not working at all? i tried running a print statement to see if the code was even running and it didnt print anything. here is my code

local tool = script.Parent
local debounce = false
local oldchar = game.Players.LocalPlayer.Character
local uis = game:GetService("UserInputService")
tool.Activated:Connect(function(click)
	local screen = Instance.new("ScreenGui", game.Players.LocalPlayer.PlayerGui)
	local button = Instance.new("TextButton", screen)
	button.Position = UDim2.new(0.858, 0,0.337, 0)
	
	button.Size = UDim2.new(0, 200,0, 50)
	button.Text = "Revert"
	button.TextScaled = true
	button.Visible = true
	button.Active = true
		screen.ResetOnSpawn = false
	local Player = game.Players.LocalPlayer
	
	local remote = game.ReplicatedStorage.Change
	
	

	
	remote:FireServer()




		
	

	button.Activated:Connect(function()
		print("hi")
		local playersService = game:GetService("Players")
		local player = game.Players.LocalPlayer

		local humDesc = playersService:GetHumanoidDescriptionFromUserId(player.UserId)
		game.Workspace.rimuru:Destroy()
		player:LoadCharacterWithHumanoidDescription(humDesc)
	


	
	end)
end)
1 Like

Line 3, The character doesn’t load immediately, so you need to wait for the character to load with the CharacterAdded event.

local character = player.CharacterAdded:Wait()
1 Like

thank you i will fix that but do you know how i could fix the gui not working when clicking problem?

Make sure there are no other existing errors in the output box, and if there aren’t any, put a print right after the tool.Activated event to make sure the code in that scope is running.

If the error still occurs, I will investigate more.

the tool activated is working fine and tthere are no errors its just not working.

Using the parent parameter in Instance.new() is deprecated and is likely the issue here. Try parenting the screengui and button in separate lines.