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

Why does the script not print "Joined Match!" when the text is the same to the match code?

Asked by 3 years ago

So I'm trying to make it so the player types in a match code and when they click join if a match has that code it prints "Joined Match". Whenever the script is like this it prints "Joined Match!":

script.Parent.MouseButton1Click:Connect(function()


    for _,v in pairs(game.Workspace:GetChildren()) do
        if v.ClassName == "Folder" then
            for _,matches in pairs(v:GetChildren()) do
                if matches.ClassName == "Folder" then
                    for _,code in pairs(matches:GetChildren())do
                        if code.Name== "MatchCode" then
                            if code.Value == "1111" then --1111 is the test code I used
                                print("Invalid Code")
                            else
                                print("Joined Match!")
                            end


                        end
                    end
                end
                end
        end
    end
end)

But when the script is like this it prints "Invalid Code":

script.Parent.MouseButton1Click:Connect(function()


    for _,v in pairs(game.Workspace:GetChildren()) do
        if v.ClassName == "Folder" then
            for _,matches in pairs(v:GetChildren()) do
                if matches.ClassName == "Folder" then
                    for _,code in pairs(matches:GetChildren())do
                        if code.Name== "MatchCode" then
                            if code.Value == script.Parent.Parent.Parent.CodeInput.Text then --CodeInput is the textbox where players put in the code (I still used the code 1111)
                                print("Invalid Code")
                            else
                                print("Joined Match!")
                            end


                        end
                    end
                end
                end
        end
    end
end)

Someone Please help!

0
Sorry "Joined Match" and "Invalid Code" are supposed to swap places COOLGUY16T 37 — 3y
0
string COOLGUY16T 37 — 3y
0
try to print `code.Value` and `script.Parent.Parent.Parent.CodeInput.Text` and their length, if they don't match then the strings are different. imKirda 4491 — 3y
0
You may also find, along with what CoolGuy16T said, that you're comparing a number/integer with a string value, regardless of whether they are equal in their raw values. As the value in the text box will be a string, you should convert it to an integer first. RoyallyFlushed 19 — 3y
View all comments (3 more)
0
Oh ok COOLGUY16T 37 — 3y
0
How would I do that? COOLGUY16T 37 — 3y
0
tostring in Lua, `tostring(5)` returns 5 as a string. imKirda 4491 — 3y

Answer this question