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

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

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)

2 comments

0

What's in the "dsactivatecoins5" script?

0

Also, I recommend not using UserInputService to detect when a user presses enter. See my answer for what to use instead.

2 answers

Use this function instead:

[textBox].FocusLost:Connect(function(enterPressed)
	if enterPressed then --checks that enter was pressed.
		--Insert your code here.
	end
end)

1 comment

0

The script is functioning even by using UserInputService, as have print statements signifying that the script is not disabled

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

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