How do you make the player jump higher when the player types a certain text into a text box

  1. What do you want to achieve? I am trying to make it so when the player types a certain text into the text box, their jump height increases. Kind of like an admin command.

  2. What is the issue? Not exactly sure what to do, or how to find the humanoid inside the script in the text box.

  3. What solutions have you tried so far? I’ve looked over the dev forum and google. I haven’t found anyone with the same idea.
    This is the script I tried. (I’m still new to coding so please don’t judge)

if script.Parent.Text == "Hi" then
	local hum = game.Players.Player.Humanoid
	hum.JumpHeight = 80
end

I’m assuming this is a LocalScript. If so, it isn’t very difficult to do so. Your code isn’t too far off how it would work, but there’s a few things wrong with it.

Try switching out the code with this:

local Players = game:GetService("Players") --// The same as game.Players, but it is better. You should always use "game:GetService()" when you try to call something like Players or ReplicatedStorage
local starterPlayer = game:GetService("StarterPlayer")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait() --// Sometimes the character doesn't load before this variable is declared, so the script will error and break. If it does not exist yet, the game will wait for the character to exist.
local humanoid: Humanoid = character:WaitForChild("Humanoid") --// WaitForChild is better because sometimes an object doesn't exist, and like in the character variable above, it will wait for an object with that name to exist. Adding the colon ":" after a variable name, and then putting a type of object will give you all of the properties of that object, which makes scripting much faster and easier. It is a useful bit of knowledge!

local textBox = script.Parent

local correctMessage = "Hi"
local jumpHeight = 80

local function FocusLost(enterPressed)
	if enterPressed then --// Checking if a boolean is directly equal to true or false is not necessary (like this: // if enterPressed == true then \\). All you need to do is say "if boolName then" to check if it is true, or "if not boolName" to check if it is false.
		local text = textBox.Text
		
		if text == correctMessage then
			humanoid.JumpHeight = jumpHeight
		else
			humanoid.JumpHeight = starterPlayer.CharacterJumpHeight
		end
	end
end

textBox.FocusLost:Connect(FocusLost) --// Listens for when the TextBox loses focus (when the player is typing). This can include an argument called "EnterPressed", which is a boolean (true or false value). This can be useful for something like what you are trying to accomplish.
1 Like

It looks like you’re on the right track! However, there are a few things you can improve on in your script.

First, instead of using game.Players.Player, you should use game.Players.LocalPlayer to get the player that is currently playing the game.

Second, you need to make sure the text entered by the player matches exactly with the text you’re checking for. For example, if the player types “hi” instead of “Hi”, your code won’t work. To avoid this, you can convert both strings to lowercase or uppercase before comparing them.

Here’s an updated version of your script that should work:

local textBox = script.Parent

textBox.FocusLost:Connect(function(enterPressed) if enterPressed then local text = textBox.Text:lower() if text == “hi” then local hum = game.Players.LocalPlayer.Character.Humanoid hum.JumpHeight = 80 end end end)

This script listens for the FocusLost event on the text box, which is triggered when the player presses enter or clicks away from the text box. It then converts the entered text to lowercase and checks if it matches “hi”. If it does, it sets the player’s jump height to 80.

Note that the script assumes that the player’s character is a child of game.Players.LocalPlayer. If your game has multiple characters or uses a different hierarchy, you may need to adjust the script accordingly.

Thanks! I will remember to use game:GetService() next time I need to work with players! :grin:

You should with anything you can see in the Explorer window, like ReplicatedStorage or StarterPlayer. This is because you can change the name of them, and the script will error if you do! It’s better practice to start using :GetService for it.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.