Well, this is the last one I publish on the subject, I solved almost everything except this. My problem is that when I start the game, if I press the key to activate the script, it gives an error of
Workspace.NUTRICORP.Crouch.KeepKeyCrouch: 54: attempt to index nil with ‘Stop’
the script itself works, but it gives that annoying error.
local uis = game:GetService("UserInputService")
local crawlAnimation = script.Parent:WaitForChild("Crawl")
local Player = game.Players.LocalPlayer
local loadedCrawlAnim
local crawlIdle = script.Parent:WaitForChild("CrawlIdle")
local loadedIdleAnim
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
local WalkSpeed = Player.PlayerGui.Configuracion:WaitForChild("WalkSpeed").Value
Player.PlayerGui.Configuracion:WaitForChild("WalkSpeed"):GetPropertyChangedSignal("Value"):Connect(function()
WalkSpeed = Player.PlayerGui.Configuracion:WaitForChild("WalkSpeed").Value
end)
local KeyText = "C"
local isCrawling = false
local KeyPressedTimestamp = 0
local AgacharseKey = Player:WaitForChild("Keys"):WaitForChild("AgacharseKey")
AgacharseKey:GetPropertyChangedSignal("Value"):Connect(function()
KeyText = AgacharseKey.Value
end)
uis.InputBegan:Connect(function(key)
if key.KeyCode.Name == KeyText then
KeyPressedTimestamp = tick()
isCrawling = true
loadedIdleAnim = humanoid:LoadAnimation(crawlIdle)
loadedIdleAnim:Play()
script.Parent.Parent:WaitForChild("Animate"):WaitForChild("run"):WaitForChild("RunAnim").AnimationId = "rbxassetid://0"
script.Parent.Parent:WaitForChild("Animate"):WaitForChild("walk"):WaitForChild("WalkAnim").AnimationId = "rbxassetid://0"
end
end)
uis.InputEnded:Connect(function(key)
if key.KeyCode.Name == KeyText then
isCrawling = false
if loadedCrawlAnim then loadedCrawlAnim:Stop() end
loadedIdleAnim:Stop()
script.Parent.Parent:WaitForChild("Animate"):WaitForChild("run"):WaitForChild("RunAnim").AnimationId = "rbxassetid://913376220"
script.Parent.Parent:WaitForChild("Animate"):WaitForChild("walk"):WaitForChild("WalkAnim").AnimationId = "rbxassetid://913402848"
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)