I want this code to be converted so it can work in a textbutton, thanks:
local UserInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local crawlAnim = humanoid:LoadAnimation(script:WaitForChild("CrawlAnim"))
local isCrawling = false
humanoid.Running:Connect(function(speed)
if speed > 0 then
crawlAnim:AdjustSpeed(1)
else
crawlAnim:AdjustSpeed(0)
end
end)
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl then
if not isCrawling then
isCrawling = true
crawlAnim:Play()
crawlAnim:AdjustSpeed(0)
humanoid.WalkSpeed = 12
humanoid.JumpPower = 0
else
crawlAnim:Stop()
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
isCrawling = false
end
end
end)
I think you can do this (that check if the player moving) :
local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
if Humanoid.MoveDirection.Magnitude > 0 then
--your code if the player is moving--
end
And I recommend you to set that if the player is crouch :
Humanoid.JumpHeight = 0
--and if the player not crouch--
Humanoid.JumpHeight = --your jump height--
local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
while wait() do
if Humanoid.MoveDirection.Magnitude > 0 then
print("Moving")
else
print("Not moving")
end
end
if you want a key and a button maybe using the ContextActionService might be better?
local contextActionService = game:GetService("ContextActionService")
local function Crouch(actionName, inputState, inputObject)
-- if the inputState is not begin exit the function
if inputState ~= Enum.UserInputState.Begin then return end
-- toggle crawling
if isCrawling == false then
isCrawling = true
crawlAnim:Play()
crawlAnim:AdjustSpeed(0)
humanoid.WalkSpeed = 12
humanoid.JumpPower = 0
else
isCrawling = false
crawlAnim:Stop()
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
end
end
-- create the action and setup the buttons image title and position
contextActionService:BindAction("Crouch", Crouch, true, Enum.KeyCode.LeftControl)
contextActionService:SetImage("Crouch", "rbxassetid://1826746856")
contextActionService:SetTitle("Crouch", "Crouch")
contextActionService:SetPosition("Crouch", UDim2.new(0.5, 0, 0.5, 0))
Ok bro ur script only needed to be modified a bit for it to do what i want i “fixed” it but would really appreciate if you modify it to be a textbutton instead, heres the modified version of ur script:
local contextActionService = game:GetService("ContextActionService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local crawlAnim = humanoid:LoadAnimation(script:WaitForChild("CrawlAnim"))
local isCrawling = false
local function Crouch(actionName, inputState, inputObject)
humanoid.Running:Connect(function(speed)
if speed > 0 then
crawlAnim:AdjustSpeed(1)
else
crawlAnim:AdjustSpeed(0)
end
end)
-- if the inputState is not begin exit the function
if inputState ~= Enum.UserInputState.Begin then return end
-- toggle crawling
if isCrawling == false then
isCrawling = true
crawlAnim:Play()
crawlAnim:AdjustSpeed(0)
humanoid.WalkSpeed = 12
humanoid.JumpPower = 0
else
isCrawling = false
crawlAnim:Stop()
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
end
end
-- create the action and setup the buttons image title and position
contextActionService:BindAction("Crouch", Crouch, true, Enum.KeyCode.LeftControl)
contextActionService:SetImage("Crouch", "rbxassetid://1826746856")
contextActionService:SetTitle("Crouch", "Crouch")
contextActionService:SetPosition("Crouch", UDim2.new(0.5, 0, 0.5, 0))