Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-2

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

Asked by 9 years ago

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

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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().

0
Well, what I am asking is, when I click the button, it only removes the clothes, but doesn't add the clothes ID. tyler46783 0 — 9y
0
Are you testing this on a ROBLOX server? It won't be able to work from offline. BlueTaslem 18071 — 9y
0
I tested it online, it just removes the clothes. tyler46783 0 — 9y
Ad

Answer this question