So I made the normal crawling animation and the crawling animations for weapons (equipping, shooting, aiming, and reloading). The animations themselves are fine, the problem is that I can’t find a way to have the weapon crawling animations play only when the weapon is equipped and if the player is actually crawling while equipping it. Here’s the code:
local crawling = false
script.Parent.Crawl.Event:Connect(function(crawl)
crawling = crawl
end)
script.Parent.Equipped:Connect(function(mouse)
equipped = true
mouse.Icon = "rbxassetid://1588092778"
weapongui:Clone().Parent = player.PlayerGui
--the problem is in these if statements
if crawling == true then
equipanim:Stop()
crawlequipanim:Play()
else
equipanim:Play()
crawlequipanim:Stop()
end
--// Functions \\--
local function Reload()
if crawling == true then
reloadanim:Stop()
crawlreloadanim:Play()
else
reloadanim:Play()
crawlreloadanim:Stop()
end
end
local function Shoot()
script.Parent.Shoot:FireServer(script.Parent.Hole.Position, mouse.Hit.Position)
if crawling == true then
shootanim:Stop()
crawlshootanim:Play()
else
shootanim:Play()
crawlshootanim:Stop()
end
ammo.Value -= 1
end
mouse.Button2Down:Connect(function()
aiming = true
if crawling == true then
aimanim:Stop()
crawlaimanim:Play()
else
aimanim:Play()
crawlaimanim:Stop()
end
workspace.CurrentCamera.FieldOfView = 40
end)
mouse.Button2Up:Connect(function()
aiming = false
aimanim:Stop()
crawlaimanim:Stop()
workspace.CurrentCamera.FieldOfView = 70
end)
script.Parent.Unequipped:Connect(function()
equipped = false
shooting = false
aiming = false
reloading = false
mouse.Icon = ""
equipanim:Stop()
shootanim:Stop()
aimanim:Stop()
reloadanim:Stop()
crawlequipanim:Stop()
crawlshootanim:Stop()
crawlaimanim:Stop()
crawlreloadanim:Stop()
if player.PlayerGui:FindFirstChild("Weapon") then
player.PlayerGui["Weapon"]:Destroy()
end
end)
end)
-- Client script located in StarterCharacterScripts that creates the crawling animations
local crawling = false
hum.Running:Connect(function(speed)
if speed > 0 then
playcrawlanim:AdjustSpeed(1)
else
playcrawlanim:AdjustSpeed(0)
end
end)
userinputservice.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
if crawling == true then
crawling = false
playcrawlanim:Stop()
hum.WalkSpeed = 25
hum.JumpPower = 50
for i, tool in pairs(char:GetChildren()) do
if tool:IsA("Tool") then
tool.Crawl:Fire(false)
end
end
else
crawling = true
playcrawlanim:Play()
hum.WalkSpeed = 8
hum.JumpPower = 0
for i, tool in pairs(char:GetChildren()) do
if tool:IsA("Tool") then
tool.Crawl:Fire(true)
end
end
end
end
end)