Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to Make Consistent Projectile-Player Interaction?

Asked by 4 years ago

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 answer

Log in to vote
0
Answered by
Tizzel40 243 Moderation Voter
4 years ago

Normally I set Up My Hit Dection Like This

local hum = Character.Humanoid-----Your Humanoid !

local hithum = false----hithum stands for Hit - humanoid (It is a Debounce)

part.Touched:Connect(function(hit)

local ehum = hit and hit.Parent:FindFirstChild("Humanoid") or hit.Parent:FindFirstChild("Humanoid")---Just in case it hits an accsessory ! (also ehum stands for Enemy Huamanoid !)

if ehum and ehum ~= hum then----if the object has found a humanoid in it and it is not your humanoid (or you)

if not hithum then---If we have not hit a humanoid then

hithum = true

----/// Do Something Here Below like :


--- ehum:TakeDamge(50)---Deals 50 Damage to the Enemy Huamanoid !



end




end


end)
0
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. Tizzel40 243 — 4y
Ad

Answer this question