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 6 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.

01game.Players.PlayerAdded:connect(function(player)
02 
03player.CharacterAdded:connect(function(character)
04 
05if player:WaitForChild("leaderstats").Money.Value == 1 then
06 
07wait(0.1)
08 
09local d = character:GetChildren()
10 
11for i=1, #d do
12 
13if (d[i].className == "Accessory") then
14 
15d[i]:remove()
16 
17end
18 
19end
20 
21end
22 
23   
24 
25if character:findFirstChild("Humanoid") ~= nil then
26 
27h = Instance.new("Accessory")
28 
29p = Instance.new("Part")
30 
31h.Name = "Hat"
32 
33p.Parent = h
34 
35p.Position = character:findFirstChild("Head").Position
36 
37p.Name = "Handle"
38 
39p.formFactor = 0
40 
41p.Size = Vector3.new(-0,-0,-1)
42 
43p.BottomSurface = 0
44 
45p.TopSurface = 0
46 
47p.Locked = true
48 
49script.Parent.AfroMesh:Clone().Parent = p
50 
51h.Parent = character
52 
53print("It should work")
54 
55h.AttachmentPos = Vector3.new(0, -0.20, 0)
56 
57wait(.1)
58 
59end
60 
61end)
62 
63end)

1 answer

Log in to vote
0
Answered by 6 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: ->

01game.Players.PlayerAdded:connect(function(player)
02    player.CharacterAdded:connect(function(character)
03        if player:WaitForChild("leaderstats").Money.Value>= 1 then -- "If they have money value"
04            wait(0.1)
05            local d = character:GetChildren()
06            for i=1, #d do
07                if (d[i].className == "Accessory") then
08                    d[i]:remove()
09                end
10            end
11            if character:findFirstChild("Humanoid") ~= nil then -- Accessory script
12                local h = Instance.new("Accessory")
13                local p = Instance.new("Part")
14                h.Name = "Hat"
15                p.Parent = h
16                p.Position = character:findFirstChild("Head").Position
17                p.Name = "Handle"
18                p.formFactor = 0
19                p.Size = Vector3.new(-0,-0,-1)
20                p.BottomSurface = 0
21                p.TopSurface = 0
22                p.Locked = true
23                script.Parent.AfroMesh:Clone().Parent = p
24                h.Parent = character
25                print("It should work")
26                h.AttachmentPos = Vector3.new(0, -0.20, 0)
27                wait(.1)
28            end
29        end --Skipped over people without value
30    end)
31end)
0
the changed is that I put the accessory script part inside SoftlockedUnderZero 668 — 6y
0
Thank you so much, this helped me out a lot. Pooglies 7 — 6y
Ad

Answer this question