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

If statement runs even when argument is not met. What am I doing wrong?

Asked by 5 years ago
Edited 5 years ago

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)
0
maybe do :GetChildren() do instead of just :children() Gameplayer365247v2 1055 — 5y
0
I did, the problem still occurs. DreamInspired 61 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

dont use :children use :GetChildren

0
Ok I will, but the problem still occurs. DreamInspired 61 — 5y
0
any errors? NickAtNick 163 — 5y
0
No DreamInspired 61 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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
0
------ Too late.... but you are using :GetChildren(), then you would have to for loop and check each existing child and check if one of them has the 'Name' "Ing" NickAtNick 163 — 5y
0
I did this, I am still experiencing the Issue though. DreamInspired 61 — 5y
0
Printed Errors? Any? NickAtNick 163 — 5y
0
No, its running the code as normal, its just there is nothing names "ing" DreamInspired 61 — 5y
View all comments (10 more)
0
huh? can u repeat that properly... Do you mean it says that "ing is an invalid member of y" ? NickAtNick 163 — 5y
0
No, i change the name of ing so that it doesn't = ing, but for some reason the code still runs. DreamInspired 61 — 5y
0
The output literally says that y.Name doesnt = ing yet it still runs the code. I have no idea why. I've asked 4 other programmers and they cant figure it out either. DreamInspired 61 — 5y
0
i think this is because of the objects in line 4, "if y.Name == "Ing" and v:IsA("Tool") then", Why don't you put the if v:IsA("Tool") statement after line #2. NickAtNick 163 — 5y
0
(In addition) and since you are comparing both different objects in an if statement. NickAtNick 163 — 5y
0
Good idea, but it didn't work. I'll figure it out eventually, but thank you for helping. I really appreciate it. You seem like a nice person. do you use disc? DreamInspired 61 — 5y
0
yeah I do.. NickAtNick 163 — 5y
0
Is it ok if I send you a friend request on roblox? DreamInspired 61 — 5y
0
okay sure, NickAtNick 163 — 5y
0
Sent DreamInspired 61 — 5y

Answer this question