Issue with custom rig collisions and animations
I made custom animations and had my friend help me set them up using a script (I’ll show it below). The collisions from the custom rig are really strange. Whenever the player steps on an elevated or lowered part/mesh, the animation rapidly replays. I’m still not sure if the problem lies within the script, the animations, or the rig itself. I’ve attached samples of each as well as a video of the problem. Thanks in advance!
Script
Chicken.__index = Chicken
local Player = game.Players.LocalPlayer
local ChickenState = Player:WaitForChild("gamestats"):WaitForChild("ChickenState");
local Bindables = game:GetService("ReplicatedStorage").Bindables
local Events = game:GetService("ReplicatedStorage").Remotes.Events
local debounce = false
local jumping = false
local inputConnection
local floorConection
local runConnection
local chickenStateConnection
local ChickenAnims = {
["Default Chicken"] = {
IDLE_ANIM = "rbxassetid://5633571340";
PECK_ANIM = "rbxassetid://6021681847";
WALK_ANIM = "rbxassetid://6020995785";
JUMP_ANIM = "rbxassetid://6115932007";
ATTACK_ANIM = "rbxassetid://5634799390";
};
["Ghost Chicken"] = {
IDLE_ANIM = "rbxassetid://5633571340";
PECK_ANIM = "rbxassetid://6021681847";
WALK_ANIM = "rbxassetid://6088950639";
JUMP_ANIM = "rbxassetid://6115932007";
ATTACK_ANIM = "rbxassetid://5634799390";
};
["Zombie Chicken"] = {
IDLE_ANIM = "rbxassetid://6115879796";
PECK_ANIM = "rbxassetid://6021681847";
WALK_ANIM = "rbxassetid://6115856356";
JUMP_ANIM = "rbxassetid://6115932007";
ATTACK_ANIM = "rbxassetid://5634799390";
}
}
function Chicken.new()
local self = setmetatable({}, Chicken)
Events.PlayerModelChanged.OnClientEvent:Connect(function()
self.Humanoid = Player.Character.Humanoid
self.Character = Player.Character
self:loadAnimations()
jumping = false
end)
return self
end
function Chicken:loadAnimations()
if inputConnection then inputConnection:Disconnect() end
if floorConection then floorConection:Disconnect() end
if runConnection then runConnection:Disconnect() end
if chickenStateConnection then chickenStateConnection:Disconnect() end
local Animator = self.Humanoid:FindFirstChildOfClass("Animator", true)
local CurrentChicken = Player:WaitForChild("leaderstats"):WaitForChild("PlayerStats").CurrentChicken.Value
local animation = Instance.new("Animation")
animation.AnimationId = ChickenAnims[CurrentChicken].WALK_ANIM
local idleAnimation = Instance.new("Animation")
idleAnimation.AnimationId = ChickenAnims[CurrentChicken].IDLE_ANIM
local jumpAnimation = Instance.new("Animation")
jumpAnimation.AnimationId = ChickenAnims[CurrentChicken].JUMP_ANIM
local peckAnimation = Instance.new("Animation")
peckAnimation.AnimationId = ChickenAnims[CurrentChicken].PECK_ANIM
local attackAnimation = Instance.new("Animation")
attackAnimation.AnimationId = ChickenAnims[CurrentChicken].ATTACK_ANIM
local AnimController = Animator:LoadAnimation(animation)
AnimController.Priority = Enum.AnimationPriority.Idle
AnimController.Looped = true
local IdleAnimController = Animator:LoadAnimation(idleAnimation)
IdleAnimController.Priority = Enum.AnimationPriority.Idle
IdleAnimController.Looped = true
local PeckAnimController = Animator:LoadAnimation(peckAnimation)
PeckAnimController.Priority = Enum.AnimationPriority.Action
PeckAnimController.Looped = false
local JumpAnimController = Animator:LoadAnimation(jumpAnimation)
JumpAnimController.Priority = Enum.AnimationPriority.Action
JumpAnimController.Looped = false
local AttackAnimController = Animator:LoadAnimation(attackAnimation)
AttackAnimController.Priority = Enum.AnimationPriority.Action
AttackAnimController.Looped = false
self.JumpAnimController = JumpAnimController
self.PeckAnimController = PeckAnimController
self.AttackAnimController = AttackAnimController
local animSpeed = 1
local defaultSpeed = 1
if CurrentChicken == "Zombie Chicken" then
animSpeed = 2
defaultSpeed = 2
end
chickenStateConnection = ChickenState.Changed:Connect(function(newValue)
if newValue == 2 then
animSpeed = animSpeed * 1.35
else
animSpeed = defaultSpeed
end
end)
if ChickenState.Value == 2 then
animSpeed = animSpeed * 1.35
else
animSpeed = defaultSpeed
end
runConnection = self.Humanoid.Running:Connect(function(speed)
if speed > 5 then
AnimController:Play(nil, nil, animSpeed)
IdleAnimController:Stop()
else
AnimController:Stop()
IdleAnimController:Play()
end
end)
inputConnection = game:GetService("UserInputService").InputBegan:Connect(function(input, gameProccessedEvent)
if input.KeyCode == Enum.KeyCode.Space and not gameProccessedEvent then
if not jumping then
jumping = true
self.JumpAnimController:Play()
self.Character.HumanoidRootPart.Velocity = Vector3.new(0, 10, 0)
end
end
end)
floorConection = self.Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
if self.Humanoid.FloorMaterial ~= Enum.Material.Air then
jumping = false
end
end)
end
function Chicken:peck()
if debounce == false then
debounce = true
self.PeckAnimController:Play()
self.PeckAnimController.Stopped:Wait()
debounce = false
return true
end
end
function Chicken:attack()
if debounce == false then
debounce = true
self.PeckAnimController:Play(0.1, 1, 2)
Bindables.AttackBegan:Fire()
self.PeckAnimController.Stopped:Wait()
Bindables.AttackEnded:Fire()
debounce = false
end
end
return Chicken```