Hello, another Dev Forum post! I am currently making a GUI crouch button with a ctrl input included. The one thing I’m having a problem is that I the button does not seem to work. The actual ctrl input works great just that the actual GUI does not work. It’s an image button but it does not seem to work at all. There are no error or messages in output and I’m really confused.
local humanoid = character:WaitForChild("Humanoid")
local crawlAnim = humanoid:LoadAnimation(script:WaitForChild("CrawlAnim"))
local isCrawling = false
local button = game.StarterGui.Crouch.ImageButton
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 = 8
humanoid.JumpPower = 0
else
crawlAnim:Stop()
humanoid.WalkSpeed = 16
humanoid.JumpPower = 30
isCrawling = false
end
end
end)
button.MouseButton1Down:Connect(function()
if not isCrawling then
isCrawling = true
crawlAnim:Play()
crawlAnim:AdjustSpeed(0)
humanoid.WalkSpeed = 8
humanoid.JumpPower = 0
else
crawlAnim:Stop()
humanoid.WalkSpeed = 16
humanoid.JumpPower = 30
isCrawling = false
end
end)
This script is located in StarterCharacterScripts and the crouch GUI is in StarterGuis. Any help is appreciated, thanks!
[EDIT]
Sorry, I wasnt checking DevForum. Pretty when you click the button, it puts the player in crouch and it works fine, but when you try to uncrouch the animation freezes and doesn’t stop. It keeps the same slow speed but does for some reason allow the player to jump. There are no errors in the output either so I don’t have any information from there. I hope this is enough information.