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

Why is this script not running when i set the disabled property to false?

Asked by 3 years ago

I am making a script where if you type "hello" and press enter in a text box, it undisables a script that adds 5 coins to a coins datastore. Here is the script that undisables the script: note: the script is in the workspace

game:GetService("UserInputService").InputBegan:Connect(function(key)
        if key.KeyCode == Enum.KeyCode.Return then
            if script.Parent.Text == "hello" then
                print("worked")
                workspace.dsactivatecoins5.Disabled = false
                local particalsuccess = Instance.new("ParticleEmitter")
                particalsuccess.Parent = game.workspace.tvscreencpp
                particalsuccess.Name = "particle"
                particalsuccess.Enabled = true
                script.Parent.Parent.Frame.text.Text = "Great job! Now click the button that says 'teleport to example' Also, here are some coins!."
                script.Parent.Parent.TextButton.Visible = true
                wait(2)
                particalsuccess.Enabled = false
            script.Parent.Parent.yaycorrect.Visible = false
            script.Parent.TextEditable = false
            script.Disabled = true
            end
            if script.Parent.Text ~= "hello" then
                print("DENIED")
                local udidbad = Instance.new("Explosion")
                udidbad.Name = "bad"
                udidbad.Parent = workspace.tvscreencpp
                script.Parent.Parent["no :("].Visible = true
                udidbad.Position = workspace.tvscreencpp.Position
                udidbad.BlastRadius = 20
                wait(2)
                udidbad:Destroy()
                script.Parent.Parent["no :("].Visible = false
            end
        end
    end)

0
What's in the "dsactivatecoins5" script? NickyPlayz2011 82 — 3y
0
Also, I recommend not using UserInputService to detect when a user presses enter. See my answer for what to use instead. NickyPlayz2011 82 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

Use this function instead:

[textBox].FocusLost:Connect(function(enterPressed)
    if enterPressed then --checks that enter was pressed.
        --Insert your code here.
    end
end)
0
The script is functioning even by using UserInputService, as have print statements signifying that the script is not disabled danielminecrafter66 18 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

It turns out that it is the script that is not functioning. i have tried using attributes, but I do not know how to use if statements with them

Answer this question