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

Whats wrong with this script?

Im trying to make it to where it Destroys The clothing, there arent any errors, nothing in the output, and my Lua Friend doesnt know whats wrong with it.

while true do
	wait()
for _,v in pairs(game.Players:GetChildren())do
local hi = v.Character.Head:findFirstChild("face")if hi then hi:Destroy() 
local mesh = v.Character.Head:findFirstChild("Mesh")if mesh then mesh:Destroy()
local clothing = v.Character:findFirstChild("Shirt")if clothing then clothing:Destroy() -- Problem here


	

end end end end end

1 answer

✓ Accepted answer

It looks like you're nesting all your if statements. The clothing:Destroy() will only be reached if there is a face and there is a head mesh and there is a shirt. This is because of the way you organize your ends. Because you put them all at the end, the statements are all nested within each other. Instead, try

while true do
	wait()
	for _,v in pairs(game.Players:GetChildren())do
		local hi = v.Character.Head:findFirstChild("face")
		if hi then
			hi:Destroy()
		end
		local mesh = v.Character.Head:findFirstChild("Mesh")
		if mesh then
			mesh:Destroy()
		end
		local clothing = v.Character:findFirstChild("Shirt")
		if clothing then 
			clothing:Destroy() -- Problem here
		end
	end 
end

Now it doesn't matter if there is no face, for example. The end for that statement is immediately after the hi:Destroy() action, and the code will continue after that end regardless of if the condition is met or not. This way, the next if statement is not within the code for the previous if statement.

1 comment

0

OH Ok

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