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

I am trying to make a uniform GUI, what is the error in this script?

local f = script.Parent local player = script.Parent.Parent.Parent.Parent.Parent s = 1138439

f.MouseButton1Down:connect(function()

	local findshirt = player.Character:FindFirstChild("Shirt")
		if findshirt then
			findshirt:remove()
							print("Destroyed")

	local findpants = player.Character:FindFirstChild("Pants")
		if findpants then
			findpants:remove()
			print("Destroyed")
			
			print("HI")
			
			if player:GetRankInGroup(s) >= 14 then
				print("Hi.")
				local newshirt = Instance.new("Shirt",player.Character)
				newshirt.ShirtTemplate = "http://www.roblox.com/asset/?id=220496690"
				local newpants = Instance.new("Pants",player.Character)
				newshirt.ShirtTemplate = "http://www.roblox.com/asset/?id=220496747"
				
			
		
		end end end

end)

1 answer

First thing first: tab your code correctly.

local f = script.Parent
local player = script.Parent.Parent.Parent.Parent.Parent
s = 1138439

f.MouseButton1Down:connect(function()
	local findshirt = player.Character:FindFirstChild("Shirt")
	if findshirt then
		findshirt:remove()
		print("Destroyed")

		local findpants = player.Character:FindFirstChild("Pants")
		if findpants then
			findpants:remove()
			print("Destroyed")
			print("HI")

			if player:GetRankInGroup(s) >= 14 then
				print("Hi.")
				local newshirt = Instance.new("Shirt",player.Character)
				newshirt.ShirtTemplate = "http://www.roblox.com/asset/?id=220496690"
				local newpants = Instance.new("Pants",player.Character)
				newshirt.ShirtTemplate = "http://www.roblox.com/asset/?id=220496747"
			end
		end
	end
end)

Now there's obviously a problem. Nothing happens if they don't have a shirt. Similarly, the group check won't happen if they don't have a Pants object.

Solution: These if statements are independent and should happen after each other, not within each other.

local f = script.Parent
local player = script.Parent.Parent.Parent.Parent.Parent
s = 1138439

f.MouseButton1Down:connect(function()
	local findshirt = player.Character:FindFirstChild("Shirt")
	if findshirt then
		findshirt:remove()
		print("Destroyed")
	end
	local findpants = player.Character:FindFirstChild("Pants")
	if findpants then
		findpants:remove()
		print("Destroyed")
		print("HI")
	end
	if player:GetRankInGroup(s) >= 14 then
		print("Hi.")
		local newshirt = Instance.new("Shirt", player.Character)
		newshirt.ShirtTemplate = "http://www.roblox.com/asset/?id=220496690"
		local newpants = Instance.new("Pants", player.Character)
		newshirt.ShirtTemplate = "http://www.roblox.com/asset/?id=220496747"
	end
end)

Consider using better variable names.

You only have to type s a few times, so you might as well make it descriptive, groupId.

You only use f once, so say button or whatever. Similarly, player is defined as script.Parent.Parent... yet script.Parent is button.


:Remove() is the preferred capitalization of :remove(). Also, :Destroy() is encouraged over :Remove().

3 comments

0

Well, what I am asking is, when I click the button, it only removes the clothes, but doesn't add the clothes ID.

0

Are you testing this on a ROBLOX server? It won't be able to work from offline.

0

I tested it online, it just removes the clothes.

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