Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
chrono2 189
8 years ago

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

Log in to vote
2
Answered by
Decemus 141
8 years ago

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.

Ad

Answer this question