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
Well, what I am asking is, when I click the button, it only removes the clothes, but doesn't add the clothes ID.
Are you testing this on a ROBLOX server? It won't be able to work from offline.
I tested it online, it just removes the clothes.