Hello, I am trying to make a jump system in which your JumpPower depends on how long you hold space down. Here’s my code so far and JumpPower doesn’t reset to default when space is released even tho I cancelled the TweenBase which is charge. I thought :Cancel stops the interpolation and resets the value?
local CAS = game:GetService("ContextActionService")
local TweenService = game:GetService("TweenService")
local character = script.Parent
local humanoid = character.Humanoid
local rootPart = humanoid.RootPart
local animator = humanoid.Animator
local anticipationAnim = animator:LoadAnimation(character:WaitForChild("Anticipation"))
local charge = TweenService:Create(humanoid, TweenInfo.new(10), {JumpPower = 200})
local function jump(_, inputState)
if inputState == Enum.UserInputState.Begin then
anticipationAnim:Play()
charge:Play()
else
anticipationAnim:Stop()
charge:Cancel()
end
end
anticipationAnim.Stopped:Connect(function()
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end)
CAS:BindAction("Jump", jump, true, Enum.KeyCode.Space)
Cancel() only resets the variables of the tweens, not the properties changed by the tween, which means if you cancel it mid animation, it won’t reset the properties to it’s original values. - TweenBase | Roblox Creator Documentation
I think we solved it. Thank you for your help guys.
local CAS = game:GetService("ContextActionService")
local TweenService = game:GetService("TweenService")
local character = script.Parent
local humanoid = character.Humanoid
local rootPart = humanoid.RootPart
local animator = humanoid.Animator
local anticipationAnim = animator:LoadAnimation(character:WaitForChild("Anticipation"))
local charge = TweenService:Create(humanoid, TweenInfo.new(10), {JumpPower = 200})
local function jump(_, inputState)
if inputState == Enum.UserInputState.Begin then
anticipationAnim:Play()
charge:Play()
else
anticipationAnim:Stop()
charge:Cancel()
humanoid.JumpPower = 50
end
end
anticipationAnim.Stopped:Connect(function()
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end)
CAS:BindAction("Jump", jump, true, Enum.KeyCode.Space)
-----[ TESTING ]-----
while wait(0.1) do
print(humanoid.JumpPower)
end