I tried enabling CanCollide, CanTouch and growing the hitbox size
I precise that this is for a fighting script
print("1")
Hitbox.Touched:Connect(function(Hit)
print("2")
“1” do prints but “2” doesnt
I tried enabling CanCollide, CanTouch and growing the hitbox size
I precise that this is for a fighting script
print("1")
Hitbox.Touched:Connect(function(Hit)
print("2")
“1” do prints but “2” doesnt
This is not enough… show the other relevant parts of the script
here’s the full script (server sided)
-- VARIABLES
local Event1 = game.ReplicatedStorage.RemoteEvents.PlayersEvents.FistHitboxEvent
-- DATAS
local TIME_TO_DELETE_M1_HITBOX = 0.5
local TIME_TO_DELETE_COUNTER_HITBOX = 0.6
local VALID_KEY = "FIGHTING_KEY"
local VALID_KEY1 = "UNBLOCK_KEY"
local SENT_KEY = "COUNTERED_EFFECTS"
local SENT_KEY1 = "COUNTERED_EFFECTS_DISABLE"
local M1_DAMAGES = 8
local COUNTER_DAMAGES = 30
local PLAYER_IS_BLOCKING
local STUN_DURATION = 5
local SPEED_WHILE_COUNTERED = 0
local NORMAL_SPEED = 16
local Debounce1 = false
--ANIMATION
local Countering = script.Countering
local Stunned = script.Stunned
local Jab1ID = "rbxassetid://86430449084596"
local Jab2ID = "rbxassetid://135513929629533"
local Jab3ID = "rbxassetid://87136688098614"
local StunID = "rbxassetid://85099143637860"
local HitingHumanoidSoundFolder = script.Sounds.HitingHumanoidSound:GetChildren()
local AirHitSoundFolder = script.Sounds.AirHitSound:GetChildren()
local BlockSound = script.Sounds.Block
-- Table pour stocker les hitboxes de BLOCK par joueur
local blockHitboxes = {}
---FUNCTION STOP ANIMATIONS
local function StopAnimation(AnimID, Player)
local humanoid = Player.Character and Player.Character:FindFirstChild("Humanoid")
if humanoid then
for _, track in ipairs(humanoid:GetPlayingAnimationTracks()) do
if track.Animation.AnimationId == AnimID then
track:Stop()
end
end
end
end
Event1.OnServerEvent:Connect(function(Player, KEY, SIZE, TYPE)
local HumanoidRootPart = Player.Character:FindFirstChild("HumanoidRootPart")
local Humanoid = Player.Character:FindFirstChild("Humanoid")
local Character = Player.Character
if not HumanoidRootPart then return end
if tostring(KEY) == VALID_KEY then
if tostring(TYPE) == "M1" then
print("M1")
local Hitbox = Instance.new("Part", Character)
Debounce1 = false
Hitbox.Size = SIZE
Hitbox.Name = "DamageHitbox"
Hitbox.CanCollide = false
Hitbox.Transparency = 0.75
Hitbox.CFrame = HumanoidRootPart.CFrame * CFrame.new(0, 0, -2) * CFrame.Angles(0, math.rad(90), 0)
Hitbox.Color = Color3.new(1, 0, 0.0156863)
local SelectedSound1 = AirHitSoundFolder[math.random(1, #AirHitSoundFolder)]
local Clone1 = SelectedSound1:Clone()
Clone1.Parent = Character
Clone1:Play()
local WeldConstraint = Instance.new("WeldConstraint", Hitbox)
WeldConstraint.Part0 = HumanoidRootPart
WeldConstraint.Part1 = Hitbox
local hitObjects = {}
Hitbox.Touched:Connect(function(Hit)
if not table.find(hitObjects, Hit) then
table.insert(hitObjects, Hit)
end
end)
task.wait(0.1) -- Attendre un peu pour accumuler les collisions
local counterHit = false
for _, Hit in ipairs(hitObjects) do
if Hit.Name == "Counter" then --COUNTERED
counterHit = true
Event1:FireClient(Player, SENT_KEY)
local CounteringPlayerCharacter = Hit.Parent
local CounteringPlayerHumanoid = Hit.Parent:FindFirstChild("Humanoid")
StopAnimation(Jab1ID, Player)
StopAnimation(Jab2ID, Player)
StopAnimation(Jab3ID, Player)
local CounteringTrack = CounteringPlayerHumanoid:LoadAnimation(Countering)
CounteringTrack:Play()
local StunnedTrack = Humanoid:LoadAnimation(Stunned)
StunnedTrack:Play()
Humanoid.WalkSpeed = SPEED_WHILE_COUNTERED
Character:FindFirstChild("DamageHitbox"):Destroy()
task.wait(STUN_DURATION)
Humanoid.WalkSpeed = NORMAL_SPEED
print("22")
Event1:FireClient(Player, SENT_KEY1)
StopAnimation(StunID, Player)
break -- On s'arrête dès qu'un counter est détecté
end
end
print("1")
Hitbox.Touched:Connect(function(Hit)
print("2")
if not counterHit then --NORMAL M1
if Hit.Parent:FindFirstChild("Humanoid") then
local victimHumanoid = Hit.Parent:FindFirstChild("Humanoid")
local SelectedSound2 = HitingHumanoidSoundFolder[math.random(1, #HitingHumanoidSoundFolder)]
local Clone2 = SelectedSound2:Clone()
Clone2.Parent = Character
Clone2:Play()
if victimHumanoid.Health >= 1 then
if Debounce1 == false then
Debounce1 = true
victimHumanoid:TakeDamage(M1_DAMAGES)
if victimHumanoid.Health <= 0 then
print("killed " .. Hit.Parent.Name)
end
end
end
end
end
end)
task.wait(TIME_TO_DELETE_M1_HITBOX)
elseif tostring(TYPE) == "BLOCK" then -----BLOCK
print("BLOCK")
local Hitbox = Instance.new("Part", workspace)
Hitbox.Size = SIZE
Hitbox.CanCollide = false
Hitbox.Transparency = 0.75
Hitbox.CFrame = HumanoidRootPart.CFrame * CFrame.Angles(0, math.rad(90), 0)
Hitbox.Color = Color3.new(0.12549, 0.92549, 1)
Hitbox.Name = "Shield"
local WeldConstraint = Instance.new("WeldConstraint", Hitbox)
WeldConstraint.Part0 = HumanoidRootPart
WeldConstraint.Part1 = Hitbox
blockHitboxes[Player] = Hitbox
elseif tostring(TYPE) == "COUNTER" then
local Hitbox = Instance.new("Part", Player.Character) ------COUNTER
Hitbox.Size = SIZE
Hitbox.CanCollide = false
Hitbox.Transparency = 0.75
Hitbox.CFrame = HumanoidRootPart.CFrame * CFrame.Angles(0, math.rad(90), 0)
Hitbox.Color = Color3.new(0.956863, 1, 0.152941)
Hitbox.Name = "Counter"
local WeldConstraint = Instance.new("WeldConstraint", Hitbox)
WeldConstraint.Part0 = HumanoidRootPart
WeldConstraint.Part1 = Hitbox
task.wait(TIME_TO_DELETE_COUNTER_HITBOX)
Hitbox:Destroy()
end
elseif tostring(KEY) == VALID_KEY1 then
if blockHitboxes[Player] then
blockHitboxes[Player]:Destroy()
blockHitboxes[Player] = nil
end
end
end)
With your hitbox, your only detecting like once right? So like when the player M1’s you quickly check any hitparts in front of them?
the touch even fires sometimes like 1/3 of the time. About verifying any hitparts, it only affects the counter section and im struggling with the M1 section which is under counters
No like you’re detecting the parts that got hit instantly right? Youre not waiting for a long time
Yes, there’s no waiting and the print is executed instantly when the touch event is firing
You should stop using .Touched
then and opt in for GetPartsInPart
Edited code:
local hitObjects = workspace:GetPartsInPart(Hitbox)
task.wait(0.1) -- Attendre un peu pour accumuler les collisions
local counterHit = false
for _, Hit in ipairs(hitObjects) do
if Hit.Name == "Counter" then --COUNTERED
counterHit = true
Event1:FireClient(Player, SENT_KEY)
local CounteringPlayerCharacter = Hit.Parent
local CounteringPlayerHumanoid = Hit.Parent:FindFirstChild("Humanoid")
StopAnimation(Jab1ID, Player)
StopAnimation(Jab2ID, Player)
StopAnimation(Jab3ID, Player)
local CounteringTrack = CounteringPlayerHumanoid:LoadAnimation(Countering)
CounteringTrack:Play()
local StunnedTrack = Humanoid:LoadAnimation(Stunned)
StunnedTrack:Play()
Humanoid.WalkSpeed = SPEED_WHILE_COUNTERED
Character:FindFirstChild("DamageHitbox"):Destroy()
task.wait(STUN_DURATION)
Humanoid.WalkSpeed = NORMAL_SPEED
print("22")
Event1:FireClient(Player, SENT_KEY1)
StopAnimation(StunID, Player)
break -- On s'arrête dès qu'un counter est détecté
end
end
print("1")
local HitParts = workspace:GetPartsInPart(Hitbox)
for _, Hit in HitParts do
if not counterHit then --NORMAL M1
if Hit.Parent:FindFirstChild("Humanoid") then
local victimHumanoid = Hit.Parent:FindFirstChild("Humanoid")
local SelectedSound2 = HitingHumanoidSoundFolder[math.random(1, #HitingHumanoidSoundFolder)]
local Clone2 = SelectedSound2:Clone()
Clone2.Parent = Character
Clone2:Play()
if victimHumanoid.Health >= 1 then
if Debounce1 == false then
Debounce1 = true
victimHumanoid:TakeDamage(M1_DAMAGES)
if victimHumanoid.Health <= 0 then
print("killed " .. Hit.Parent.Name)
end
end
end
end
end
end
when an object is moving, the .Touched events chance of triggering decreases by a load.
.Touched is notorious for not triggering a lot of the time, how to fix it? You cant sadly.
Your best bet is swapping to Raycasts, or one of the workspace:GetPartsBoundInX() Methods.
Or an already existing hitbox module :]
I see now that @sonic_848 has brought a solution, but I think Id still give more explanation
I don’t like writing a lot, which explains why you don’t see me give specifics, but I mean like I gave a link for them to read the specifics of it. You could explain it to them if you want
It works propely thank you !
aaaaaa
Yeah I know, I was trying to call you out, just showing the facts here so they dont have to go and read documents n stuffs
Thank you for your explaination i will find out about it
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.