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

What do i have to add to make the jumppower to 0 when the player is crawled?

Asked by 2 years ago

Hi :), I want that the player can't jump while being crawled but idk how to do it.

local uis = game:GetService("UserInputService")
local crawlAnimation = script:WaitForChild("Crawl")
local crawlIdle = script:WaitForChild("CrawlIdle")
local isCrawling = false
local humanoid = script.Parent:WaitForChild("Humanoid")
local sprintscript = humanoid.Parent.SprintScript
local StarterGui = game:GetService('StarterGui')
local loadedIdleAnim = humanoid:LoadAnimation(script:WaitForChild("CrawlIdle"))
local loadedCrawlAnim = humanoid:LoadAnimation(script:WaitForChild("Crawl"))

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()


uis.InputBegan:Connect(function(key)
    if key.KeyCode == Enum.KeyCode.C then
        if isCrawling then
            isCrawling = false
            if loadedCrawlAnim then loadedCrawlAnim:Stop() end  
            loadedIdleAnim:Stop()           
            game.ReplicatedStorage.OnCrouchBegun:FireServer(humanoid, 16, 50)
            sprintscript.Disabled = false
            humanoid.HipHeight = 0
            StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
        elseif not isCrawling then
            isCrawling = true   
            loadedIdleAnim = humanoid:LoadAnimation(crawlIdle)
            loadedIdleAnim:Play()           
            game.ReplicatedStorage.OnCrouchBegun:FireServer(humanoid, 8, 0)
            sprintscript.Disabled = true
            humanoid.HipHeight = -2
            StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
        end
    end 
end)

game:GetService("RunService").RenderStepped:Connect(function()

    if not isCrawling then return end
    if humanoid.MoveDirection.Magnitude > 0 then
        if not loadedCrawlAnim then loadedCrawlAnim = humanoid:LoadAnimation(crawlAnimation) end
        if loadedCrawlAnim.IsPlaying == false then loadedCrawlAnim:Play() end   
    else
        loadedCrawlAnim:Stop()
        loadedIdleAnim:Play()
    end
end)

1 answer

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
2 years ago

humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false) disables the ability to jump, changing false to true enables it back:

local uis = game:GetService("UserInputService")
local crawlAnimation = script:WaitForChild("Crawl")
local crawlIdle = script:WaitForChild("CrawlIdle")
local isCrawling = false
local humanoid = script.Parent:WaitForChild("Humanoid")
local sprintscript = humanoid.Parent.SprintScript
local StarterGui = game:GetService('StarterGui')
local loadedIdleAnim = humanoid:LoadAnimation(script:WaitForChild("CrawlIdle"))
local loadedCrawlAnim = humanoid:LoadAnimation(script:WaitForChild("Crawl"))

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()


uis.InputBegan:Connect(function(key)
    if key.KeyCode == Enum.KeyCode.C then
        if isCrawling then
            isCrawling = false
            if loadedCrawlAnim then loadedCrawlAnim:Stop() end  
            loadedIdleAnim:Stop()           
            game.ReplicatedStorage.OnCrouchBegun:FireServer(humanoid, 16, 50)
            sprintscript.Disabled = false
            humanoid.HipHeight = 0
            humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
            StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
        elseif not isCrawling then
            isCrawling = true   
            loadedIdleAnim = humanoid:LoadAnimation(crawlIdle)
            loadedIdleAnim:Play()           
            game.ReplicatedStorage.OnCrouchBegun:FireServer(humanoid, 8, 0)
            sprintscript.Disabled = true
            humanoid.HipHeight = -2
            humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
            StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
        end
    end 
end)

game:GetService("RunService").RenderStepped:Connect(function()

    if not isCrawling then return end
    if humanoid.MoveDirection.Magnitude > 0 then
        if not loadedCrawlAnim then loadedCrawlAnim = humanoid:LoadAnimation(crawlAnimation) end
        if loadedCrawlAnim.IsPlaying == false then loadedCrawlAnim:Play() end   
    else
        loadedCrawlAnim:Stop()
        loadedIdleAnim:Play()
    end
end)

i didn't change anything only added lines 33 and 24

0
if this does not work then edit your question and put the LocalScript that handles OnCrouchBegun remote event on the client imKirda 4491 — 2y
0
this is because it's possible that humanoid states may only be enabled/disabled in LocalScript and not basic Script i am not sure about that imKirda 4491 — 2y
0
it worked thx :) iiDark_St4le 19 — 2y
Ad

Answer this question