For some reason the code in the first If statement is still being run despite the fact that the argument has not been reached (y.Name isn’t Ing, yet the code still runs). When I rearrange the code the output literally says “Ing is not a valid member of mesh part” yet it still decides to run the code anyways. What am I doing wrong???
01 | game.ReplicatedStorage.IngAdded.OnServerEvent:connect( function (player) |
02 | for i,v in pairs (player.character:GetChildren()) do |
03 | for x,y in pairs (script.Parent:GetChildren()) do |
04 | if y.Name = = "Ing" and v:IsA( "Tool" ) then -- The code here still runs even though y.Name is not Ing. |
05 | v.Activated:connect( function () |
06 | Activated = true |
07 | y.Name = v.Name |
08 | print ( "New Value created" ) |
09 | local newv = Instance.new( "NumberValue" ) |
10 | newv.Parent = script.Parent |
11 | y.Transparency = 0 |
12 | end ) |
13 | v.Deactivated:connect( function () |
14 | Activated = false |
15 | end ) |
16 | elseif v:IsA( "Tool" ) and y.Name = = v.Name then |
17 | v.Activated:connect( function () |
18 | Activated = true |
19 | print ( "Adding to Existing Value" ) |
20 | end ) |
21 | v.Deactivated:connect( function () |
22 | Activated = false |
23 | end ) |
24 | end |
25 | end |
26 | end |
27 | end ) |
dont use :children use :GetChildren
For line #2 and #3 which is.
1 | for i,v in pairs (player.character:children()) do |
2 | for x,y in pairs (script.Parent:children()) do |
:children() is deprecated.
So instead use :GetChildren():
1 | for i,v in pairs (player.character:GetChildren()) do |
2 | for x,y in pairs (script.Parent:GetChildren()) do |