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

How would I go about making this short to the point where I could have 11x of these in one script?

Asked by 5 years ago

I have this script that gives a player a hat if they have a value, but I wan't to have it so it determines if the player has it, giving the hat to the player, in one script. I don't know if theres a way to do this but if there is, please help. heres the script.

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        if player:WaitForChild("leaderstats").Hats.Value == 1 then -- "If they have money value"
            wait(0.5)
            local d = character:GetChildren()
            for i=1, #d do
                if (d[i].className == "Accessory") then
                    d[i]:remove()
                end
            end
            if character:findFirstChild("Humanoid") ~= nil then -- Accessory script
                local h = Instance.new("Accessory")
                local p = Instance.new("Part")
                h.Name = "Hat"
                p.Parent = h
                p.Position = character:findFirstChild("Head").Position
                p.Name = "Handle"
                p.BrickColor = BrickColor.new("Really black") 
                p.formFactor = 0
                p.Size = Vector3.new(-0,-0,-1)
                p.BottomSurface = 0
                p.TopSurface = 0
                p.Locked = true
                script.Parent.AfroMesh:Clone().Parent = p
                h.Parent = character
                print("It should work")
                h.AttachmentPos = Vector3.new(0, -0.20, 0)
                wait(.1)
            end
        end --Skipped over people without value
    end)
end)
1
Put a findfirstchild to check if they have a hat maybe? Luka_Gaming07 534 — 5y
0
Use a function. Fifkee 2017 — 5y
0
:remove is deprecated, use :Destroy(). SuperSamyGamer 316 — 5y

Answer this question