Hello
I need hep with two scripts, where is wrong
- I press the SHIFT key and the player crouches
- I release the key and the player jumps, according to the length of time the SHIFT key is held
-----------first--------------
local player = game.Players.LocalPlayer
local humanoid = player.Character:WaitForChild("Humanoid")
local isCrouching = false
local crouchStartTime = 0
local jumpPowerMultiplier = 2.5 -- Úprava síly skoku
local crouchAnimId = "rbxassetid://180436334"
local crouchAnim = Instance.new("Animation")
crouchAnim.AnimationId = crouchAnimId
local loadedAnim = humanoid:LoadAnimation(crouchAnim)
loadedAnim.Looped = false
local function onKeyPress(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
isCrouching = true
crouchStartTime = tick()
loadedAnim:Play()
end
end
local function onKeyRelease(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
isCrouching = false
crouchStartTime = 0
loadedAnim:Stop()
end
end
local function update()
if isCrouching then
local crouchDuration = tick() - crouchStartTime
local jumpPower = humanoid.JumpPower * (1 + crouchDuration * jumpPowerMultiplier)
humanoid.JumpPower = jumpPower
end
end
game:GetService("UserInputService").InputBegan:Connect(onKeyPress)
game:GetService("UserInputService").InputEnded:Connect(onKeyRelease)
game:GetService("RunService").Heartbeat:Connect(update)
----------------second------------
local function onCharacterAdded(character)
character:WaitForChild("Humanoid").StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Jumping then
local humanoid = character:WaitForChild("Humanoid")
if humanoid:GetState() == Enum.HumanoidStateType.Crouching then
humanoid.JumpPower = humanoid.JumpPower / (1 + humanoid:GetStateTime(Enum.HumanoidStateType.Crouching))
end
end
end)
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(onCharacterAdded)
end)
Thank you for every one help
Codycheck