Hello, i have a tool which when it lands on a character, it will perform a mauling action. But the problem is whenever the victim(player) or the tool player leaves the game or changing team, respawned, removed both of them wouldnt get restored and they will continue to do the mauling action.
Here is the main part about it inside the code:
jumpremote.OnServerEvent:Connect(function(plr, hitsmth)
local toolowner = getToolOwnerPlayer(tool)
local char = toolowner.Character or toolowner.CharacterAdded:Wait()
local humanoid = char:FindFirstChildOfClass("Humanoid")
local root = char:FindFirstChild("HumanoidRootPart")
local victim = hitsmth.Parent
local humofvictim = victim:FindFirstChildOfClass("Humanoid")
local rootofvictim = victim:FindFirstChild("HumanoidRootPart")
local ownerstats = char:FindFirstChild("Stats")
local attmultiplier = (ownerstats and ownerstats:FindFirstChild("AttackMultiplier")) and ownerstats.AttackMultiplier.Value
local victimstats = victim:FindFirstChild("Stats")
local victimdefend = (victimstats and victimstats:FindFirstChild("Defensive")) and victimstats.Defensive.Value
if not humofvictim or not rootofvictim then return end
local cmaultrack = humanoid:LoadAnimation(cmaulanim)
local vmaultrack = humofvictim:LoadAnimation(vmaulanim)
local victimPlayer = players:GetPlayerFromCharacter(victim)
if victimPlayer and isSameTeam(toolowner, victimPlayer) then return end
char:SetAttribute("tanked")
cmaultrack:Play()
vmaultrack:Play()
connection:Disconnect()
root.Anchored = true
rootofvictim.Anchored = true
local pointlight = Instance.new("PointLight")
pointlight.Color = Color3.new(1, 0, 0)
pointlight.Parent = rootofvictim
pointlight.Brightness = 10
pointlight.Range = 15
if humofvictim and humofvictim.Health > 0 and humanoid.Health > 0 then
while humofvictim.Health > 0 and humanoid.Health > 0 do
local damage = damagecal:Calculate(mauldmgper,attmultiplier,victimdefend)
humofvictim:TakeDamage(damage)
maul:Play()
humanoid.AutoRotate = false
humofvictim.AutoRotate = false
victim:SetAttribute("CanAttack", false)
char:SetAttribute("CanAttack", false)
if root.Anchored ~= true or rootofvictim.Anchored ~= true then
rootofvictim.Anchored = true
root.Anchored = true
end
dealdmgremote:FireClient(toolowner, victim, damage)
root.CFrame = CFrame.new(root.Position, Vector3.new(rootofvictim.Position.X, root.Position.Y, rootofvictim.Position.Z))
rootofvictim.CFrame = root.CFrame * CFrame.new(0, 0, -1)
rootofvictim.CFrame = CFrame.new(rootofvictim.Position, Vector3.new(root.Position.X, rootofvictim.Position.Y, root.Position.Z))
task.wait(0.3)
end
if humofvictim.Health <= 0 then
char:SetAttribute("CanAttack", true)
char:SetAttribute("tanked", nil)
victim:SetAttribute("CanAttack", true)
humanoid.AutoRotate = true
humofvictim.AutoRotate = true
rootofvictim.Anchored = false
root.Anchored = false
cmaultrack:Stop()
vmaultrack:Stop()
pointlight:Destroy()
end
if humanoid.Health <= 0 then
char:SetAttribute("CanAttack", true)
char:SetAttribute("tanked", nil)
victim:SetAttribute("CanAttack", true)
humanoid.AutoRotate = true
humofvictim.AutoRotate = true
rootofvictim.Anchored = false
root.Anchored = false
cmaultrack:Stop()
vmaultrack:Stop()
pointlight:Destroy()
end
end
end)
if your remote event is firing once these won’t go off since you already have more than 0 in health
from this if humofvictim and humofvictim.Health > 0 and humanoid.Health > 0 then
you need to use the Humanoid.Died event or use Humanoid.Changed event for those Humanoids then put the code i quoted (above) inside that event so it stops the animation.
try and see. Idk since i dont have your rbx place. also its hard to tell how your firing your event you could just use a elseif statement in
jumpremote.OnServerEvent:Connect(function(plr, hitsmth)
local toolowner = getToolOwnerPlayer(tool)
local char = toolowner.Character or toolowner.CharacterAdded:Wait()
local humanoid = char:FindFirstChildOfClass("Humanoid")
local root = char:FindFirstChild("HumanoidRootPart")
local victim = hitsmth.Parent
local humofvictim = victim:FindFirstChildOfClass("Humanoid")
local rootofvictim = victim:FindFirstChild("HumanoidRootPart")
local ownerstats = char:FindFirstChild("Stats")
local attmultiplier = (ownerstats and ownerstats:FindFirstChild("AttackMultiplier")) and ownerstats.AttackMultiplier.Value
local victimstats = victim:FindFirstChild("Stats")
local victimdefend = (victimstats and victimstats:FindFirstChild("Defensive")) and victimstats.Defensive.Value
if not humofvictim or not rootofvictim then return end
local cmaultrack = humanoid:LoadAnimation(cmaulanim)
local vmaultrack = humofvictim:LoadAnimation(vmaulanim)
local victimPlayer = players:GetPlayerFromCharacter(victim)
if victimPlayer and isSameTeam(toolowner, victimPlayer) then return end
char:SetAttribute("tanked")
cmaultrack:Play()
vmaultrack:Play()
connection:Disconnect()
root.Anchored = true
rootofvictim.Anchored = true
local pointlight = Instance.new("PointLight")
pointlight.Color = Color3.new(1, 0, 0)
pointlight.Parent = rootofvictim
pointlight.Brightness = 10
pointlight.Range = 15
if humofvictim and humofvictim.Health > 0 and humanoid.Health > 0 then
while humofvictim.Health > 0 and humanoid.Health > 0 do
local damage = damagecal:Calculate(mauldmgper,attmultiplier,victimdefend)
humofvictim:TakeDamage(damage)
maul:Play()
humanoid.AutoRotate = false
humofvictim.AutoRotate = false
victim:SetAttribute("CanAttack", false)
char:SetAttribute("CanAttack", false)
if root.Anchored ~= true or rootofvictim.Anchored ~= true then
rootofvictim.Anchored = true
root.Anchored = true
end
dealdmgremote:FireClient(toolowner, victim, damage)
root.CFrame = CFrame.new(root.Position, Vector3.new(rootofvictim.Position.X, root.Position.Y, rootofvictim.Position.Z))
rootofvictim.CFrame = root.CFrame * CFrame.new(0, 0, -1)
rootofvictim.CFrame = CFrame.new(rootofvictim.Position, Vector3.new(root.Position.X, rootofvictim.Position.Y, root.Position.Z))
task.wait(0.3)
end
elseif humofvictim.Health <= 0 or humanoid.Health <= 0 then
if humofvictim.Health <= 0 then
char:SetAttribute("CanAttack", true)
char:SetAttribute("tanked", nil)
victim:SetAttribute("CanAttack", true)
humanoid.AutoRotate = true
humofvictim.AutoRotate = true
rootofvictim.Anchored = false
root.Anchored = false
cmaultrack:Stop()
vmaultrack:Stop()
pointlight:Destroy()
end
if humanoid.Health <= 0 then
char:SetAttribute("CanAttack", true)
char:SetAttribute("tanked", nil)
victim:SetAttribute("CanAttack", true)
humanoid.AutoRotate = true
humofvictim.AutoRotate = true
rootofvictim.Anchored = false
root.Anchored = false
cmaultrack:Stop()
vmaultrack:Stop()
pointlight:Destroy()
end
end
end)
when i respawn while the mauling action is still performing the victim would get stuck and the maul animations, root part anchoring and autorotate wouldnt get restored like when they died, the dead handler works fine i dont think you need to change it
i think i know what u mean, pls send a video anyway!
i think its because of your while loop -
jumpremote.OnServerEvent:Connect(function(plr, hitsmth)
local toolowner = getToolOwnerPlayer(tool)
local char = toolowner.Character or toolowner.CharacterAdded:Wait()
local humanoid = char:FindFirstChildOfClass("Humanoid")
local root = char:FindFirstChild("HumanoidRootPart")
local victim = hitsmth.Parent
local humofvictim = victim:FindFirstChildOfClass("Humanoid")
local rootofvictim = victim:FindFirstChild("HumanoidRootPart")
local ownerstats = char:FindFirstChild("Stats")
local attmultiplier = (ownerstats and ownerstats:FindFirstChild("AttackMultiplier")) and ownerstats.AttackMultiplier.Value
local victimstats = victim:FindFirstChild("Stats")
local victimdefend = (victimstats and victimstats:FindFirstChild("Defensive")) and victimstats.Defensive.Value
if not humofvictim or not rootofvictim then return end
local cmaultrack = humanoid:LoadAnimation(cmaulanim)
local vmaultrack = humofvictim:LoadAnimation(vmaulanim)
local victimPlayer = players:GetPlayerFromCharacter(victim)
if victimPlayer and isSameTeam(toolowner, victimPlayer) then return end
char:SetAttribute("tanked")
cmaultrack:Play()
vmaultrack:Play()
connection:Disconnect()
root.Anchored = true
rootofvictim.Anchored = true
local pointlight = Instance.new("PointLight")
pointlight.Color = Color3.new(1, 0, 0)
pointlight.Parent = rootofvictim
pointlight.Brightness = 10
pointlight.Range = 15
if humofvictim and humofvictim.Health > 0 and humanoid.Health > 0 then
while humofvictim.Health > 0 and humanoid.Health > 0 do
local damage = damagecal:Calculate(mauldmgper,attmultiplier,victimdefend)
humofvictim:TakeDamage(damage)
maul:Play()
humanoid.AutoRotate = false
humofvictim.AutoRotate = false
victim:SetAttribute("CanAttack", false)
char:SetAttribute("CanAttack", false)
if root.Anchored ~= true or rootofvictim.Anchored ~= true then
rootofvictim.Anchored = true
root.Anchored = true
end
dealdmgremote:FireClient(toolowner, victim, damage)
root.CFrame = CFrame.new(root.Position, Vector3.new(rootofvictim.Position.X, root.Position.Y, rootofvictim.Position.Z))
rootofvictim.CFrame = root.CFrame * CFrame.new(0, 0, -1)
rootofvictim.CFrame = CFrame.new(rootofvictim.Position, Vector3.new(root.Position.X, rootofvictim.Position.Y, root.Position.Z))
task.wait(0.3)
if humofvictim.Health <= 0 or humanoid.Health <= 0 then
if humofvictim.Health <= 0 then
char:SetAttribute("CanAttack", true)
char:SetAttribute("tanked", nil)
victim:SetAttribute("CanAttack", true)
humanoid.AutoRotate = true
humofvictim.AutoRotate = true
rootofvictim.Anchored = false
root.Anchored = false
cmaultrack:Stop()
vmaultrack:Stop()
pointlight:Destroy()
end
if humanoid.Health <= 0 then
char:SetAttribute("CanAttack", true)
char:SetAttribute("tanked", nil)
victim:SetAttribute("CanAttack", true)
humanoid.AutoRotate = true
humofvictim.AutoRotate = true
rootofvictim.Anchored = false
root.Anchored = false
cmaultrack:Stop()
vmaultrack:Stop()
pointlight:Destroy()
end
break --//Stops the while loop
end
end
end
end)
jumpremote.OnServerEvent:Connect(function(plr, hitsmth)
local toolowner = getToolOwnerPlayer(tool)
local char = toolowner.Character or toolowner.CharacterAdded:Wait()
local humanoid = char:FindFirstChildOfClass("Humanoid")
local root = char:FindFirstChild("HumanoidRootPart")
local victim = hitsmth.Parent
local humofvictim = victim:FindFirstChildOfClass("Humanoid")
local rootofvictim = victim:FindFirstChild("HumanoidRootPart")
local ownerstats = char:FindFirstChild("Stats")
local attmultiplier = (ownerstats and ownerstats:FindFirstChild("AttackMultiplier")) and ownerstats.AttackMultiplier.Value
local victimstats = victim:FindFirstChild("Stats")
local victimdefend = (victimstats and victimstats:FindFirstChild("Defensive")) and victimstats.Defensive.Value
if not humofvictim or not rootofvictim then return end
local cmaultrack = humanoid:LoadAnimation(cmaulanim)
local vmaultrack = humofvictim:LoadAnimation(vmaulanim)
local victimPlayer = players:GetPlayerFromCharacter(victim)
if victimPlayer and isSameTeam(toolowner, victimPlayer) then return end
char:SetAttribute("tanked")
cmaultrack:Play()
vmaultrack:Play()
connection:Disconnect()
root.Anchored = true
rootofvictim.Anchored = true
local pointlight = Instance.new("PointLight")
pointlight.Color = Color3.new(1, 0, 0)
pointlight.Parent = rootofvictim
pointlight.Brightness = 10
pointlight.Range = 15
if humofvictim then
while humofvictim.Health > 0 and humanoid.Health > 0 do
local damage = damagecal:Calculate(mauldmgper,attmultiplier,victimdefend)
humofvictim:TakeDamage(damage)
maul:Play()
humanoid.AutoRotate = false
humofvictim.AutoRotate = false
victim:SetAttribute("CanAttack", false)
char:SetAttribute("CanAttack", false)
if root.Anchored ~= true or rootofvictim.Anchored ~= true then
rootofvictim.Anchored = true
root.Anchored = true
end
dealdmgremote:FireClient(toolowner, victim, damage)
root.CFrame = CFrame.new(root.Position, Vector3.new(rootofvictim.Position.X, root.Position.Y, rootofvictim.Position.Z))
rootofvictim.CFrame = root.CFrame * CFrame.new(0, 0, -1)
rootofvictim.CFrame = CFrame.new(rootofvictim.Position, Vector3.new(root.Position.X, rootofvictim.Position.Y, root.Position.Z))
task.wait(0.3)
if humofvictim.Health <= 0 or humanoid.Health <= 0 then
char:SetAttribute("CanAttack", true)
char:SetAttribute("tanked", nil)
victim:SetAttribute("CanAttack", true)
humanoid.AutoRotate = true
humofvictim.AutoRotate = true
rootofvictim.Anchored = false
root.Anchored = false
cmaultrack:Stop()
vmaultrack:Stop()
pointlight:Destroy()
break --//Stops the while loop
end
end
end
end)
this should work.^
respawning? in your video all i see is you spawning the target, you maul them and then you change. Only issue was the animation not stopping? if im correct?
its because you aren’t entirely losing health you’re changing your whole character with a setup humanoid of a health > 0.
what you should do is when changing character - set the health on it to 0 when changing on the current then change to the new character u selected then this should stop.