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

My audio script has a problem with playing?

This one should be easy to figure out. Basically, this script plays the music ID that is inputted to the textbox. The problem is, if the focus is lost and I keep pressing enter the sound keeps restarting. Any help with this?

game:GetService('UserInputService').InputBegan:Connect(function(Input, onGui)
	    if Input.UserInputType == Enum.UserInputType.Keyboard then
        if Input.KeyCode == Enum.KeyCode.Return and textBox.Focused then
			local sound = game.Workspace.Sound
			sound.SoundId = "rbxassetid://"..textBox.Text
			sound:Play()
end end end)

Thanks!

1 answer

✓ Accepted answer

You can use Textbox.FocusLost to detect enter being pressed instead of UIS

textBox.FocusLost:Connect(function(enter,input)
	if enter or input then -- remove input if you only want the sound to play when pressing enter
		local sound = game.Workspace.Sound
         sound.SoundId = "rbxassetid://"..textBox.Text
         sound:Play()
	end
end)

This should only run once until Focus is regained

1 comment

0

Thank you so much! :D

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