I have had a very peculiar bug bothering me for a while, and nothing I do seems to fix it. I have a boss in my game who has various attacks. Leading up to that boss is a path littered with parts that will kill the player when touched (which simulate cliffs). Whenever the boss fires a certain attack, a touch event is added to his axe to detect if the player is touching it. However, I have discovered that when the player touches the axe (this happens 75% of the time), the kill parts fire a touch event that causes the player to die. In the linked video, I have the kill part that was touched become transparent so I can see which one was touched, and the part of the player that was touched will be cloned into the workspace and given a highlight so that I can see where the touch event was fired. These next scripts are parts of larger scripts:
The axe touch event:
local CanBeHit = {} --loading all the players still in the boss fight into the table
for _,player in players do table.insert(CanBeHit,player.Character) end
Attacking = true --indicates for the humanoid to stop checking for attacking conditions and to stop walking
humanoid:MoveTo(NPP.Position) --stop the humanoid walking
noob:PivotTo(CFrame.lookAt(NPP.Position,Vector3.new(character.PrimaryPart.Position.X,NPP.Position.Y,character.PrimaryPart.Position.Z)))--face the player
if method == "Slash" then
--adding an additional table bc two axes
local CanBeHitRight = table.clone(CanBeHit)
animations.Slash:Play()
animations.Slash:GetMarkerReachedSignal("Swing"):Connect(function()
NPP.Swing:Play()
end)
task.wait(1)
local rightBladeConnection = noob.RightHitBox.Touched:Connect(function(hit)
if hit.Parent and table.find(CanBeHit,hit.Parent) then
table.remove(CanBeHit,table.find(CanBeHit,hit.Parent))
hit.Parent.Humanoid:TakeDamage(DamageProcessor.processDamage(nil, noob, 10, hit.Parent))
end
end)
local leftBladeConnection = noob.LeftHitBox.Touched:Connect(function(hit)
if hit.Parent and table.find(CanBeHitRight,hit.Parent) then
table.remove(CanBeHitRight,table.find(CanBeHitRight,hit.Parent))
hit.Parent.Humanoid:TakeDamage(DamageProcessor.processDamage(nil, noob, 10, hit.Parent))
end
end)
animations.Slash.Stopped:Wait()
if rightBladeConnection then
rightBladeConnection:Disconnect()
end
if leftBladeConnection then
leftBladeConnection:Disconnect()
end
Attacking = false
The script for the kill parts (which are named RagdollParts because they rag doll the player (to make them fall off the cliff) before killing them):
for _, RagdollPart:Part in ipairs(game.Workspace.ParkourAreaBorders:GetDescendants()) do
if RagdollPart.Name == "RagdollPart" then
--task.spawn(function()
local damageProcessor = require(game.ReplicatedStorage:WaitForChild("DamageProcessor"))
RagdollPart.Touched:Connect(function(hit)
local hitPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
if hitPlayer and not hitPlayer:GetAttribute("Ragdolling") then
print(hit)
print(hit.Parent)
print(hit.Parent.Parent)
local hitclone = hit:Clone()
hitclone.Anchored = true
hitclone.Parent = workspace
hitclone.Material = Enum.Material.Neon
hitclone.Transparency = 0
Instance.new('Highlight',hitclone)
RagdollPart.Transparency = .5
hitPlayer:SetAttribute("Ragdolling", true)
hitPlayer:SetAttribute("CanRun", false)
local dies = RagdollPart:GetAttribute("Dies")
task.spawn(function()
game.ReplicatedStorage.Remotes.Ragdoll:Fire(hit.Parent, dies, RagdollPart:GetAttribute("RagdollTime"))
end)
task.wait(RagdollPart:GetAttribute("RagdollTime") or 2.9)
if not dies then
local damage = damageProcessor.processDamage(hitPlayer, nil, RagdollPart:GetAttribute("Damage"), nil)
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(damage)
end
hitPlayer:SetAttribute("Ragdolling", false)
hitPlayer:SetAttribute("CanRun", true)
end
end)
end
end
Finally, here is a video of the player getting kill from not touching the part (ignore the low quality of the animations and model lol):
For some strange reason, I realized that if these lines are removed, this never happens:
local rightBladeConnection = noob.RightHitBox.Touched:Connect(function(hit)
if hit.Parent and activePlayers[hit.Parent] and activePlayers[hit.Parent] == true then
activePlayers[hit.Parent] = false
hit.Parent.Humanoid:TakeDamage(DamageProcessor.processDamage(nil, noob, 10, hit.Parent))
end
end)
local leftBladeConnection = noob.LeftHitBox.Touched:Connect(function(hit)
if hit.Parent and OtherAxeTable[hit.Parent] and OtherAxeTable[hit.Parent] == true then
OtherAxeTable[hit.Parent] = false
hit.Parent.Humanoid:TakeDamage(DamageProcessor.processDamage(nil, noob, 10, hit.Parent))
end
end)