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

All players get hat even though its only for players with a 1?

Asked by 5 years ago

I have this script that if you have a money value, you get a hat, but for some reason people without a money value get it to? Could someone help me with this.

game.Players.PlayerAdded:connect(function(player)

player.CharacterAdded:connect(function(character)

if player:WaitForChild("leaderstats").Money.Value == 1 then

wait(0.1)

local d = character:GetChildren()

for i=1, #d do

if (d[i].className == "Accessory") then

d[i]:remove()

end

end

end



if character:findFirstChild("Humanoid") ~= nil then

h = Instance.new("Accessory")

p = Instance.new("Part")

h.Name = "Hat"

p.Parent = h

p.Position = character:findFirstChild("Head").Position

p.Name = "Handle"

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)

end)

1 answer

Log in to vote
0
Answered by 5 years ago

This is because you left the two if statements at lines 5 and 25 completely separate. This means if a player has a value of 1, they would get their hat removed then get the accessory. However, because the hat part of the script is outside of the value, anyone can get it. Try this: ->

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        if player:WaitForChild("leaderstats").Money.Value>= 1 then -- "If they have money value"
            wait(0.1)
            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.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)
0
the changed is that I put the accessory script part inside SoftlockedUnderZero 668 — 5y
0
Thank you so much, this helped me out a lot. Pooglies 7 — 5y
Ad

Answer this question