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???
game.ReplicatedStorage.IngAdded.OnServerEvent:connect(function(player) for i,v in pairs (player.character:GetChildren()) do for x,y in pairs (script.Parent:GetChildren()) do if y.Name == "Ing" and v:IsA("Tool") then -- The code here still runs even though y.Name is not Ing. v.Activated:connect(function() Activated = true y.Name = v.Name print ("New Value created") local newv = Instance.new("NumberValue") newv.Parent = script.Parent y.Transparency = 0 end) v.Deactivated:connect(function() Activated = false end) elseif v:IsA("Tool") and y.Name == v.Name then v.Activated:connect(function() Activated = true print ("Adding to Existing Value") end) v.Deactivated:connect(function() Activated = false end) end end end end)
dont use :children use :GetChildren
For line #2 and #3 which is.
for i,v in pairs (player.character:children()) do for x,y in pairs (script.Parent:children()) do
:children() is deprecated.
So instead use :GetChildren():
for i,v in pairs (player.character:GetChildren()) do for x,y in pairs (script.Parent:GetChildren()) do