Basically i need help on how to remake this so when the player leaves the part called RightFoot Box, it won't take any damage.It works now even if he leaves its hitbox the player still dies.
Hitboxes['Right Foot Box'].Touched:Connect(function(hit) if not is_blinded or not is_right_grab or not is_left_grab or not is_stomped or Titan.Humanoid.Health <= 0 then return end if not is_leftleg_tendon or not is_rightleg_tendon then return end local char = hit.Parent local Player = game.Players:GetPlayerFromCharacter(char) if not Player then return end if not char:FindFirstChild('Humanoid') then return end is_stomped = false local Stomp = Titan.Humanoid:LoadAnimation(Titan.Animations.Stomp) Stomp:AdjustSpeed(5) Stomp:Play() for i, track in pairs(Titan.Humanoid:GetPlayingAnimationTracks()) do if track.Name == 'Stomp' and not is_stomping then char.Humanoid:TakeDamage(100) wait(3) is_stomped = true return end end wait(Stomp.Length) char.Humanoid:TakeDamage(100) wait(1) is_stomped = true end)
to check if the player stopped touching the part:
Object.Touched:Connect(function(hit) -- code here end) Object.TouchEnded:Connect(function(hit) -- code here end)
Ok so this might be what you are looking for. The only problem is when you are constantly going in and out of this hitbox, sometimes it will not register a hit. It is bc of the way how a server sees a player. Basically it is impossible to do a highly accurate hit reg by using one server script
local hitboxPart = script.Parent local touchingHumanoidRootParts = {} -- we gonna save humanoid root parts that are already touching. Notice I said parts, not players hitboxPart.Touched:Connect(function(part) if part.Name ~= "HumanoidRootPart" then return end -- the best option is to check for humanoid root part local Player = game.Players:GetPlayerFromCharacter(part.Parent) -- checking for a humanoid by your way if not Player then return end if not part.Parent:FindFirstChild('Humanoid') then return end if table.find(touchingHumanoidRootParts, part) then return end -- checking for this specific humanoid root part out of all humanoid root parts we saved. If there is one - ignoring this event table.insert(touchingHumanoidRootParts, part) -- else saving this humanoid root part so this character won't be damaged again while he is touching hitbox -- the rest of your script part.Parent.Humanoid.Health = part.Parent.Humanoid.Health - 20 end) hitboxPart.TouchEnded:Connect(function(part) if part.Name ~= "HumanoidRootPart" then return end if not part.Parent:FindFirstChild('Humanoid') then return end if table.find(hitboxPart:GetTouchingParts(), part) then return end -- making sure that hitbox is no longer touching humanoid root part. If this humanoid root part found in all touching parts of hitbox then we are ignoring this event. This is a very important step and this is how we detect "fake touch events" if not table.find(touchingHumanoidRootParts, part) then return end -- checking for this specific humanoid root part out of all humanoid root parts we saved. If there are none - nothing needs to be done about this table.remove(touchingHumanoidRootParts, table.find(touchingHumanoidRootParts, part)) -- else removing this humanoid root part so this character can be damaged by this hitbox end)
We are using a HumanoidRootPart
as a main hitreg part of a character, I find it the best way how to do the thing with preventing multiple damages on a character. You probably don't understand how tables works, it is essential to understand how tables works in this situation. If you have questions, leave them below (but i have to go to sleep so i can only answer tomorrow)
table functions such as table.find()
, table.remove()