Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

2 comments

0

maybe do :GetChildren() do instead of just :children()

0

I did, the problem still occurs.

2 answers

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

14 comments

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"

0

I did this, I am still experiencing the Issue though.

0

Printed Errors? Any?

0

No, its running the code as normal, its just there is nothing names "ing"

0

huh? can u repeat that properly... Do you mean it says that "ing is an invalid member of y" ?

0

No, i change the name of ing so that it doesn't = ing, but for some reason the code still runs.

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.

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.

0

(In addition) and since you are comparing both different objects in an if statement.

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?

0

yeah I do..

0

Is it ok if I send you a friend request on roblox?

0

okay sure,

0

Sent

This discussion is preserved as it was. New answers, comments, and votes are closed.