um localscript pro roblox que quando o player digitar alguma coisa no textbox dntro de…
- User
um localscript pro roblox que quando o player digitar alguma coisa no textbox dntro de uma gui faça o character dele dar play em uma animation. porem so quando ele clicar nas teclas de digitar do celular/teclado, e adicone um debounce na animaçao de 0.1 segundos
- Assistant
Here's a Roblox LocalScript that accomplishes what you're asking for:
local player = game.Players.LocalPlayer local TextBox = script.Parent -- Adjust this if the script isn't a direct child of the TextBox local debounce = false -- Replace "AnimationIDHere" with your actual animation ID local animationId = "rbxassetid://AnimationIDHere" local Animation = Instance.new("Animation") Animation.AnimationId = animationId local function playAnimation() if not debounce then debounce = true -- Play the animation local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:FindFirstChildOfClass("Humanoid") if humanoid then local animationTrack = humanoid:LoadAnimation(Animation) animationTrack:Play() end -- Debounce timer of 0.1 seconds task.delay(0.1, function() debounce = false end) end end -- Function to handle input began in the TextBox local function onInputBegan(input) if input.UserInputType == Enum.UserInputType.Keyboard then playAnimation() end end -- Connect for keyboard input in the TextBox (for PC) TextBox.InputBegan:Connect(onInputBegan) -- Connect to Text changes in the TextBox (for mobile) TextBox:GetPropertyChangedSignal("Text"):Connect(function() if TextBox:IsFocused() then playAnimation() end end)Instructions:
-
Place this LocalScript inside your TextBox GUI element. If it's not a direct child, adjust the
TextBoxvariable to correctly reference your TextBox. -
Replace
"AnimationIDHere"with the ID of the animation you want to play. Make sure the animation is properly uploaded to Roblox and is accessible. -
This script handles both PC and mobile inputs:
- On PC, it listens for keyboard input when the TextBox is focused.
- On mobile devices, it listens for changes to the Text property while the TextBox is focused.
-
Debounce Implementation:
- A debounce is used to prevent the animation from playing too rapidly.
- The debounce duration is set to 0.1 seconds as per your requirement.
Explanation:
- The
playAnimationfunction checks the debounce and plays the animation if it's allowed. - We listen to
TextBox.InputBeganto detect when a key is pressed while typing in the TextBox on PC. - We use
TextBox:GetPropertyChangedSignal("Text")to detect when the Text changes on mobile devices, which typically happens when the user types something using the touch keyboard. - The
TextBox:IsFocused()check ensures that the animation only plays when the user is actively typing in the TextBox. - The debounce prevents the animation from triggering multiple times within 0.1 seconds.
Note:
- Make sure that the player's character has a Humanoid and that the animation you're trying to play is compatible with the character model.
Testing:
- Test the script both on PC and on a mobile device (or using Roblox Studio's emulator) to ensure that it behaves as expected.
Let me know if you need further assistance or adjustments to the script!
-