#Enter number gui always saying wrong even when right

58 messages · Page 1 of 1 (latest)

proud shuttle
#
debounce = false

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild('Humanoid') then
        if debounce then
            return
        end
        debounce = true

        local plr = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
        local gui = script.Parent:FindFirstChild("codegui")  -- Make sure the GUI is named correctly
        if gui then
            local randomNumber = math.random(100, 999)
            print(randomNumber)

            gui.Frame.code.Text = randomNumber
            print(randomNumber)
            local clone = gui:Clone()
            clone.Parent = plr:FindFirstChild("PlayerGui")

            wait(3.5)
            local enteredCode = tostring(plr.PlayerGui:FindFirstChild("codegui"):FindFirstChild("Frame"):FindFirstChild("entercode").Text)
            print(enteredCode)
            if enteredCode == randomNumber then
                plr.PlayerGui.codegui:Destroy()
            else
                plr.Character.Humanoid.Health = 0
            end
        else
            print("GUI not found.")
        end
    end
    wait()
    debounce = false
end)

Im trying to make a system where if you enter a correct code it gets rid of your gui, I have tried using string.find but that just comes up with nothing but works for both incorrect and correct things, but if I compare it to the number to check if its right then it kills the player no matter what

(its saying what I put in the text box is nil)

pulsar wasp
#

That's because you are using string.find, if it's found anywhere in the string, it will return the starting index

#

Meaning that it will accept anything that has the key in it

#

You can just compare both strings, the received and the actual, no need to find inside of it

#

Like

"MyKey" == "NotMyKey" equals false

proud shuttle
#

im not tho

wicked echo
proud shuttle
#

and its saying what i put in the text box is nil

#

its saying what I enter is nil

nova osprey
#

among us

proud shuttle
nova osprey
wicked echo
#

the nil is from the tonumber converted enteredCode?

proud shuttle
#

yes

split needleBOT
#

studio** You are now Level 1! **studio

nova osprey
#
local debounce = false

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild('Humanoid') then
        if debounce then
            return
        end
        debounce = true

        local plr = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
        local gui = script.Parent:FindFirstChild("codegui")  -- Make sure the GUI is named correctly
        if gui then
            local randomNumber = math.random(100, 999)
            print(randomNumber)

            gui.Frame.code.Text = tostring(randomNumber)
            print(randomNumber)
            
            local clone = gui:Clone()
            clone.Parent = plr:FindFirstChild("PlayerGui")

            wait(3.5)
            
            local entercode = plr.PlayerGui:FindFirstChild("codegui"):FindFirstChild("Frame"):FindFirstChildOfClass("TextBox")
            if entercode then
                local enteredCode = tostring(entercode.Text)
                print(enteredCode)
                if enteredCode == tostring(randomNumber) then
                    plr.PlayerGui.codegui:Destroy()
                else
                    plr.Character.Humanoid.Health = 0
                end
            else
                print("Enter code textbox not found.")
            end
        else
            print("GUI not found.")
        end
    end
    wait()
    debounce = false
end)

#

try

#

be sure

#

its indexed

#

correctly

proud shuttle
#

now its just saying nothing

#

like invisible

nova osprey
#

si ut diesbt eveb reacg ebtercide xd

#

wtf language

wicked echo
#

you could compare both Frame.Code text and enteredCode text without needing to convert tho

nova osprey
#

I speak

split needleBOT
#

studio** You are now Level 14! **studio

nova osprey
#

it not even reach the condition

#

xd

proud shuttle
#

IM SO STUPID WHY DIDNT I THINK OF THAT

#

oh wait-

wicked echo
#

anyway idk why tonumber failed converting and tostring too

proud shuttle
#

its positive no matter what now

#
local debounce = false

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild('Humanoid') then
        if debounce then
            return
        end
        debounce = true

        local plr = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
        local gui = script.Parent:FindFirstChild("codegui")  -- Make sure the GUI is named correctly
        if gui then
            local randomNumber = math.random(100, 999)
            print(randomNumber)

            gui.Frame.code.Text = tostring(randomNumber)
            print(randomNumber)

            local clone = gui:Clone()
            clone.Parent = plr:FindFirstChild("PlayerGui")

            wait(3.5)

            if plr.PlayerGui.codegui.Frame.entercode.Text == plr.PlayerGui.codegui.Frame.code.Text then
                plr.PlayerGui.codegui:Destroy()
            else
                plr.Character.Humanoid.Health = 0
            end
            else
                print("Enter code textbox not found.")
            end
        else
            print("GUI not found.")
        end
    wait()
    debounce = false
end)
#

this is the code now

#

and same error

wicked echo
#

check both values in the else statement

proud shuttle
#

now its just printing an invis character

wicked echo
#

but what variable

proud shuttle
#

plr.PlayerGui.codegui.Frame.entercode.Text

#

its not assigned to a variable

wicked echo
#

uhm that's from the textbox right?

proud shuttle
#

yea

split needleBOT
#

studio** You are now Level 2! **studio

wicked echo
#

and you sure when testing you actually entered the value in the textbox? like not just write it

proud shuttle
#

yes

#

it actually shows in the actual textbox

wicked echo
# proud shuttle

the gui you're setting the value is the same gui player holds?

proud shuttle
#

current code:

local debounce = false

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild('Humanoid') then
        if debounce then
            return
        end
        debounce = true

        local plr = game:GetService('Players'):FindFirstChild(hit.Parent.Name)
        local plrobject = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
        local gui = script.Parent:FindFirstChild("codegui")  -- Make sure the GUI is named correctly
        
        
        if gui then
            local randomNumber = math.random(100, 999)
            print(randomNumber)

            gui.Frame.code.Text = tostring(randomNumber)
            print(randomNumber)

            local clone = gui:Clone()
            clone.Parent = plr:FindFirstChild("PlayerGui")

            wait(4)
            
            print(game:GetService('Players'):FindFirstChild(hit.Parent.Name).PlayerGui.codegui.Frame.entercode.Text)
            
            if plr.PlayerGui.codegui.Frame.entercode.Text == plr.PlayerGui.codegui.Frame.code.Text then
                plrobject.PlayerGui.codegui:Destroy()
            else
                plrobject.Character.Humanoid.Health = 0
            end
            else
                print("Enter code textbox not found.")
            end
        else
            print("GUI not found.")
        end
    wait()
    debounce = false
end)```
wicked echo
#

if you clone it, why don't you just use the clone variable instead of writting all that

#

clone.Frame.entercode.Text