I'm trying to make projectile attacks that don't feel inconsistent or buggy. I first made a script that can spawn in one or more parts that fly through the air to act as hit boxes. At first I decided to use part.Touched to activate a function that would have the player that was hit take damage, but in testing, it constantly seemed like the hit boxes obviously didn't hit on one players screen (normally the one getting hit), but it counted as a hit anyways. I decided to change up the script and this is what I was left with:
hitBox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and db == false and hit.Parent ~= player.Character then
local function GetTouchingParts(part)
local connection = part.Touched:Connect(function() end)
local results = part:GetTouchingParts()
connection:Disconnect()
return results
end
local results = GetTouchingParts(hitBox)
print(#results)
for i,v in pairs(results) do
if v.Parent:FindFirstChild("Humanoid") and db == false then
v.Parent:WaitForChild("Humanoid"):TakeDamage(25)
db = true
if v.Parent.Humanoid.Health >= 0 then
local tag = Instance.new("ObjectValue",v.Parent.Humanoid)
tag.Value = player
tag.Name = "Creator"
end
local walkspeed = v.Parent.Humanoid.WalkSpeed
v.Parent.Humanoid.WalkSpeed = 4
wait(0.5)
v.Parent.Humanoid.WalkSpeed = walkspeed
end
end
end
end)
end)
This is all part of a larger script where hitBox is defined as a new part in the workspace so ignore the extra ends. This script works much better, but I still run into a problem that's the exact opposite of what I had before. When a hit box obviously passes through a player, it does no damage and print(#results) shows up as 0. Is there a solution to this? Should I be using a different method to handle hit box-player interaction? Is Roblox just a buggy engine and I should switch to unity or rethink my combat system?
Here's the game link for anyone interested: https://www.roblox.com/games/4907040843/Untitled-lemark23-Project?refPageId=b04a450c-064f-4b00-931a-f6a589acbe5a&nl=true&nl=true&nl=true

1 comment
This One Will Detect a hit If It Hitted an accessory or something else. This Will Also Compare the enemy's humanoid to your humanoid to see if the person who got hit was or was not you.