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

How would i fix Gui that breaks on reset?

The Variables would print

but the objects wont appear and change the players name

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local backpack = plr.Backpack
local light = game.Lighting

local deb = false
script.Parent.FocusLost:connect(function(a)
	if deb then return end
	deb = true
	print ' deb is true'
	if a then
		local nt = char:GetChildren()--Finds if theres one already existing
		for a, ta in pairs(char:GetChildren()) do
			if ta:findFirstChild('Name') then
				ta:Destroy()
				char.Head.Transparency = 0
				print 'found a model'
			end
		end
	end
	
	
	local ta = Instance.new("Model", char)
	ta.Name = script.Parent.Text.. " : " ..plr.Name
	local ch = char.Head:Clone()
	ch.Parent = ta
	print 'made a new model and heal'
	
	local human = Instance.new("Humanoid", ta)
	human.Name = "Name"
	print 'new humanoid'
	
	
	local w = Instance.new("Weld", ch)
	w.Part0 = ch 
	w.Part1 = char.Head
	char.Head.Transparency = 1
	print 'new weld'
	
	wait(5)
	deb = false
	print ' done'
	
	
end)

1 answer

✓ Accepted answer

In my experience it is common for GUI scripts to reload before the new characters are spawned. I believe what is happening is that once you reset, the GUI script reloads, sets char as the dead character, and then respawns the character.

I would suggest to wait for CharacterAdded at the end of your script as well to get the new character in case if the character found was the dead one.

    wait(5)
    deb = false
    print ' done'


end)

char = plr.CharacterAdded:wait()

1 comment

0

Thx u were the only one to answer me all day

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