It works when the Hit Box's parent is the workspace but when the parent of the Hit Box is the character, it doesn't work.
Here's the script to add the hitbox:
game.Players.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(c)
print("Character Added")
local hb = game.ServerStorage.ABHitBox:Clone()
hb.Parent = c
hb.Anchored = false
hb.Name = "ABHitbox"
local cons = Instance.new("WeldConstraint")
cons.Part0 = c.UpperTorso
cons.Part1 = hb
cons.Parent = hb
hb.Position = c.UpperTorso.Position
end)
end)
Here's the script to play the animation when a character touches the hitbox:
local feet = script.Parent.LeftUpperLeg and script.Parent.RightUpperLeg and script.Parent.LowerTorso and script.Parent.UpperTorso
local events = game.ReplicatedStorage.Events
local animid = 4937349103
local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id="..animid
feet.Touched:Connect(function(part)
print(part.Name)
if part.Name == "ABHitBox" then
print("It is a hitbox")
if part.DoingMove.Value == true then
local playanim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(anim)
playanim:Play()
print("Played Animation")
end
end
end)
I don't understand how it plays when its parent is the workspace but doesn't when its the character.
