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

Removing morph with GUI button?

So, I've been workin' on on this GUI that removes the morph named "Chest" from player's character. It works, but when I click the remove button 2 times, and then morph again, the remove wont work anymore. I tried to fix, but there's an error in the script. :c

wait(1)
player = game:GetService("Players").LocalPlayer
gui = script.Parent
button = gui.Button
button.MouseButton1Down:connect(function()
local found = player.Character:findFirstChild("Chest")

if found then
end
end
found:Destroy()
player.Character.Humanoid.MaxHealth = 100
wait(0.1)
end

thank thee

1 answer

Please tab your code correctly.

So what's the point of that if statement on line 08? It's basically saying, "if found exists then do nothing" Also, the end on line 10 should be removed, because it is not needed. You have an if statement and a function, so you only need two ends. The final end, on line 14, should have a ) around it, to close the connect() method. The wait() on line 13 is not really needed either.

Here's how it should be fixed:

wait(1)
player = game:GetService("Players").LocalPlayer
gui = script.Parent
button = gui.Button

button.MouseButton1Down:connect(function()
	local found = player.Character:findFirstChild("Chest")
	if found then
		found:Destroy()
		player.Character.Humanoid.MaxHealth = 100
	end
end)

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