Hello,
So I have a crouch gui for my game, but the problem is, it doesn’t always work!
I mean by this, I will crouch, but un-crouching is buggy! Sometimes, the crouch gui will go white when un-crouching(which should happen) and the speed will go back to 16, but the animation doesn’t stop playing!
This doesn’t always happen 1/6 chance. However, I need to make it so this doesn’t happen.
Here is my local script:
local UserInputService = game:GetService('UserInputService')
local Character = script.Parent
local Humanoid = Character:WaitForChild('Humanoid')
local isCrawling = false
local Player = game.Players.LocalPlayer
local Debounce = false
local CrouchGui = Player.PlayerGui:WaitForChild('CrouchGui')
UserInputService.InputBegan:Connect(function(Input)
if Player.PlayerGui.CrouchGui.Enabled == true and Player:WaitForChild('CanCrouch').Value == true then
if Input.KeyCode == Enum.KeyCode.LeftControl and Debounce == false then
Debounce = true
if not isCrawling then
Player.PlayerGui.CrouchGui.Crouch.ImageColor3 = Color3.fromRGB(49, 128, 255)
isCrawling = true
game.ReplicatedStorage.Events.CrawlEvent:FireServer(true)
wait(1)
Debounce = false
else
Player.PlayerGui.CrouchGui.Crouch.ImageColor3 = Color3.fromRGB(255, 255, 255)
game.ReplicatedStorage.Events.CrawlEvent:FireServer(false)
isCrawling = false
wait(1)
Debounce = false
end
end
end
end)
Server Script:
game.ReplicatedStorage.Events.CrawlEvent.OnServerEvent:Connect(function(Player,crawlOrNot)
local Humanoid = workspace:FindFirstChild(Player.Name):WaitForChild('Humanoid')
if crawlOrNot == true then
crawlAnim = Humanoid:LoadAnimation(script:WaitForChild('CrawlAnim'))
crawlAnim:Play()
Humanoid.Parent.HumanoidRootPart.CanCollide = false
crawlAnim:AdjustSpeed(0)
Humanoid.WalkSpeed = 8
Humanoid.JumpPower = 0
else
crawlAnim:Stop()
Humanoid.Parent.HumanoidRootPart.CanCollide = true
Humanoid.WalkSpeed = 16
Humanoid.JumpPower = 40
end
Humanoid.Running:Connect(function(speed)
if speed > 0 then
crawlAnim:AdjustSpeed(1)
else
crawlAnim:AdjustSpeed(0)
end
end)
end)
Thanks for any help!