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