Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

3 comments

0

if this does not work then edit your question and put the LocalScript that handles OnCrouchBegun remote event on the client

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

0

it worked thx :)

This discussion is preserved as it was. New answers, comments, and votes are closed.