UIS Input check

Hey! How can I check if a player chatted something, and then jumped? (With acceptance of about 1 second delay from the chat to jumping)

Because UIS.InputBegan and if chatting doesn’t work exactly as I’d like it to work.

Have you tried Player.Chatted? It might be what you are looking for. You can check if a player jumps by using Humanoid.Jumping.

1 Like

Yes I already have a Player.Chatted function for my previous needs.

Current part of the code:

if Words[1] == JJs[1] then
   if status.Status.Text == "20 JJs remaining!" then
--something happens here you don't need to know what it is
end

So if I did it like this, it could work, or?

if Words[1] == JJs[1] and Humanoid.Jumping then
   if status.Status.Text == "20 JJs remaining!" then
--something happens here you don't need to know what it is
end

Not quite, .Jumping is an event. So I would do something like this:

local humanoid: Humanoid = charactersHumanoid -- Assign humanoid here
local connection: RBXScriptConnection = nil
connection = humanoid.Jumping:Connect(function()
	if playerHasSaidWord() then
		jumpingJackComplete()
		connection:Disconnect() -- Connect again when jumping jacks are required again
	end
end)

Note: Make sure to disconnect the event if the humanoid dies!

Thanks, though. I’d need to make it so the player has to say something first and then jump. I think that your script checks the jump first, right?

Well, yes and no. The function playerHasSaidWord() is supposed to be where you check if the player has said the word or not.

Basically, whenever they jump it checks if they have said the word they need to say before they jumped. So the functionality would be:
When player jumps and they have said the word, do whatever needs to be done.

How could I check if they said something already before they jumped tho? Because I can just check whether they’re saying something after they jumped.

Or am I wrong?

use the Player.Chatted() function to set a variable on and then set it to off exactly one second later.

It’d just be two variables that are the os.time() of the player’s last actions regarding Jumping and Chatting. If the player jumps, updates that last time they did that and same with Chatting.

Within the function that updates the jumping, you’d check the difference between the two times and if it’s within one second, then you can call a function.

Example:

local LastJump
local LastChat

local Player = game:GetService("Players").LocalPlayer

local RequiredText = "" -- What needs to be said by the player

Player.Character.Humanoid.Jumping:Connect(function()

	LastJump = os.time()

	if LastChat ~= nil then

		if os.difftime(LastChat, LastJump) <= 1 then
		
			print("BOOM BOOM POW") -- Do stuff
		end
	end
end)

Player.Chatted:Connect(function(Message)

	if string.find(Message, RequiredText) then

		LastChat = os.time()
	end
end)

I didn’t test this, so it might not work xD

1 Like

Thanks for the code! The problem is that, I intend to do this function (jump and chat) multiple times. (Around 20 to be exact). So this script is pretty difficult for use like this.

No, you are checking if they said something before they jumped. When you jump you check if they have said it. Something like this:

player.Chatted:Connect(function(message) -- Just guessing message goes there. Can't remember
	if player.Character:GetAttribute("JJ_Count") - 1 == tonumber(message) then
		player.Character:SetAttribute("JJ_Said", true)
		player.Character:SetAttribute("JJ_Count", tonumber(message))
	end
end)

humanoid.Jumping:Connect(function()
	if player.Character:GetAttribute("JJ_Said") then
		player.Character:SetAttribute("JJ_Said", nil)
		if player.Character:GetAttribute("JJ_Count") == 0 then
			-- All jumping jacks are done
		end
	end
end)

Note: This code must be modified to work as intended, primarily the disconnection of events and clearing of attributes once everything is done. In this case, the code player.Character:GetAttribute("JJ_Said") is the equivalent to playerHasSaidWord(). This might not be exactly what you are looking for, but it should be pretty easy to modify.

This code assumes that the attribute JJ_Count as been set. As mentioned, you need to modify this. This code is primarily for demonstration purposes of what I meant.

I think you meant the difference was that mine was to check if they’ve said anything before jumping while yours is if he said something specific before jumping.

He didn’t specify it was something specific he was looking for in regards to what players are messaging before jumping.

Also, your code doesn’t check if they had jumped within the past second, just if they’ve said a keyword in general before jumping.

My previous message with the script has been revised, @Nyxifier

Well, it looks like he is planning on making jumping jacks, and while he didn’t say a specific word needed to be said he has:

which I assumed was that he wanted to see if they has said a specific word. In order to implement a time check in my code you would just need to add

player.CharacterSetAttribute("JJ_MsgTime", os.time())

in the same place JJ_Count and JJ_Said is being set. To see if the time has passed, get the attribute and compare it with the time.