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

How can I make these functions only work if the player isn't chatting(And other similar issues)?

This script executes a function whenever the player presses the spacebar, and then executes another whenever they release it, but there are a few problems with it.

Firstly, is there any way to make sure that it only triggers if the player isn't chatting?

Second, it's kinda glitchy... Sometimes if you release the spacebar too quickly, it holds the animation infinitely. Is there any way to fix that?

player = game.Players.LocalPlayer
character = game.Players.LocalPlayer.Character
humanoid = character.Humanoid
local chest = game.ReplicatedStorage.Animations
function onPress(inputObject, gameProcessedEvent)
	glideanim = humanoid:LoadAnimation(chest.Glide)
    if inputObject.KeyCode == Enum.KeyCode.Space then
        print("FLY MY SON")
		wait(0.3)
		glideanim:Play()
		local cape = character.Chest.Cape.Mesh
		cape.Scale = Vector3.new(6,-3.4,1.7)
		cape.Parent.GlideEffect.P = 1250
		humanoid.WalkSpeed = 60
    end
end

function OnRelease(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.Space then
	 print("FALL YOU FOOL")
        glideanim:Stop()
		local cape = character.Chest.Cape.Mesh
		cape.Scale = Vector3.new(1.6,-3.4,1.7)
		cape.Parent.GlideEffect.P = 0
		humanoid.WalkSpeed = 16
		
    end
end

local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:connect(onPress)
UserInputService.InputEnded:connect(OnRelease)

1 answer

✓ Accepted answer

gameProcessedEventmeans when the player is doing anything related to coreGuis, like the chat. In order to fix this, simply put a conditional statement checking to see if the gameProcessedEvent is false.

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