I'm new to CAService and keyboardInput in general, so how exactly would I go about executing part of a function once a certain key is pressed, (and holding) then when the key is released running the other half? So far I've tried running a portion of it when the UserInputState.Begin (the main animation), then the other portion when UserInputState.End (the idle animation). And for some reason it seems that only the first half runs.
local CAService = game:GetService("ContextActionService")
local deb = false
local function first(actionName, inputState, inputObj)
if not deb then
if inputState == Enum.UserInputState.Begin then
deb = true
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local Animation = Instance.new("Animation")
Animation.Name = 'Swimming';
Animation.AnimationId = "rbxassetid://2130790796"
local track = character.Humanoid:LoadAnimation(Animation)
track.Looped = true
track:Play()
if track.IsPlaying == true and Animation.Name == 'Swimming' then
character.Humanoid.WalkSpeed = 16
elseif inputState == Enum.UserInputState.End then
local Animation = Instance.new("Animation")
Animation.Name = 'Treading';
Animation.AnimationId = "rbxassetid://2130697426"
local track = character.Humanoid:LoadAnimation(Animation)
track.Looped = true
track:Play()
if track.IsPlaying == true and Animation.Name == 'Treading' then
character.Humanoid.WalkSpeed = 0
deb = false
end
end
end
end
end
CAService:BindAction("keyPress", first, false, Enum.KeyCode.Up)

1 comment
Alright man thanks, I'll try that!