This is quite literally my first post on here, but nonetheless…
I’m having struggles with detections for hitbox.
This hitbox script is for a charging attack that I’m working on.
I’ve gotten the part where if the hitbox touches another player, it’ll deal damage to them and stop the charge.
I’m then trying to make it to where if the player ends up colliding with a wall it’ll stop the charge.
However, instead of the outcome that I’m looking forward, the player still continues to charge even after the hitbox comes into contact with wall. My belief is that it’s touching the player parts rather than registering the other parts. But I’m not too sure about it.
Apologies if the code isn’t good, but I’ve been stuck on this for a while and I haven’t found a solution yet.
local hitbox = script.Parent
local creator = hitbox:FindFirstChild('creator')
local amount = 15
task.delay(0.2,function()
hitbox:Destroy()
end)
hitbox.Touched:Connect(function(part)
local ownertool = game.Workspace:FindFirstChild(creator.Value).Charge
if part.Parent:FindFirstChild("Humanoid") and part.Parent.Name ~= ownertool.Parent.Name
and part.Name ~= "Handle" then -- If hitbox ends up hitting a player
local hum = part.Parent:FindFirstChild("Humanoid")
ownertool["Has Hit"].Value = true
hum:TakeDamage(amount)
print(part.Name)
hitbox:Destroy()
else -- If hitbox ends up hitting a wall.
local ownertool = game.Workspace:FindFirstChild(creator.Value).Charge
print(part.Name)
ownertool["Has Hit"].Value = true
hitbox:Destroy()
end
end)
I would think that the charge isnt stopping because you are not giving damage, when its detecting if you hit a wall. However, if its not printing the part name, then its not even getting that.
That shouldn’t make a difference, but thats good to know. Let me look this over and I’ll see if anything stands out. Ok, if I want to test, Do I need to put a wall, and do I need to put anything inside the wall, such as an .Value?
You’ll need to put a wall, but you don’t need to have a value on that wall though. Because putting a value in too many objects when your making a map can be rough.
It seems just as is, that its hitting the ‘effect’ of blocks that are displayed as it charges, so the charge only lasts, like 1 second and I hear a ‘hit’ sound.
Also, I saw your notes on the disabled script, and animations are replicated. So if you play an animation on a client, it will show up on other clients.
I must’ve been messing around with the code earlier and forgot to add the prevention of detecting player parts. Silly me. (still not the solution though as interacting with the wall doesn’t do as it’s suppose too)
Also, animations pass over to other people even if it’s not in my game?
I’m still going through it. So, when you charge it creates a box (hit box) and this is what is supposed to do damage to other players, and also to stop a charge upon hitting something like a wall. Correct?
So why do you recreate the hitbox multiple times? I would think that you would just attach the hitbox to the player who is charging, so it would move along with them, hitting anything they run into. Is there a reason you do it differently?
I’ve actually tried to weld the hitbox to the player before and it didn’t really go as planned. Hence why I decided to do a drag effect instead, not sure if I’d be effective though. (not sure if the “drag effect” thing made sense)
The reason I ask, is because when you place a block into the world, it will not cause a hit detection unless something is moved by physics inside of the block. So just parenting them in, as an anchored block, near an anchored wall, wont produce a collision, even if they overlap
I would create the hitbox, as soon a they hold the tool, or even have it a permanent part of the tool.
But only check for a ‘hit’ collision when the tool is active.
Let me see if I can rewrite your code just a bit, and see if I can get a good result and then I’ll post what I found.