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

How do I make my script hit multiple targets while also having debounce?

Asked by 4 years ago

The problem is that I want my attack to be able to deal damage to multiple targets but if I don't use a debounce then it will deal that damage like 50 times to each player, and if I use a debounce it will only damage one player. How would I make it so it can hit multiple targets while it also has a debounce?

I tried using a table so when a player gets hit their name gets puts inside the table, but I don't know what to do next

This is what the hit detection looks like right now:

ShockWave2.Touched:Connect(function(hit)
        local humanoid = hit.Parent:FindFirstChild("Humanoid")
        if humanoid then
            local Table = {}
            table.insert(Table,game.Players:GetPlayerFromCharacter(hit.Parent))
0
I fixed it up for you, finally got access to studio lol. cmgtotalyawesome 1418 — 4y
0
To answer your question on how to learn stuff like that on your own, I personally watched a lot of tutorials on youtube and read up on the roblox developer wiki a lot. Also, a good practice in scripting is to have a clear plan of how you will accomplish something before you start writing. You knew you wanted a table, but you didn't know how to check for a player. Next step is research and learn. cmgtotalyawesome 1418 — 4y
0
Also if my answer did end up helping, it would be greatly appreciated if you accepted it :) cmgtotalyawesome 1418 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You're on the right path with the table, now all you need to do is check if the player is in the table before damage. If the player is in the table, don't do damage, otherwise deal the amount you want. To go through the whole table we can use a for loop. This would make your code look like the following block:

local Table = {} -- Define the table first or else you will make a new one every hit.

ShockWave2.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
        local found = false
        for i = 1, #Table do
            if Table[i] == hit.Parent.Name then
                found = true
            end 
        end
        if found == false then      
            table.insert(Table,game.Players:GetPlayerFromCharacter(hit.Parent).Name)
            humanoid:TakeDamage(30)
            found = true
            wait(3)
            for i = 1, #Table do
                if Table[i] == hit.Parent.Name then
                    table.remove(Table, i)
                end
            end             
        end             
    end
end)

This should now create debounces for separate players, however, I have no access to studio currently so I couldn't test. Feel free to tell me any errors and I will correct them for you.

0
So I tried the script and added the damage but for some reason it does no damage now: Guest_NumberNotFound 19 — 4y
0
Also it doesn't give any errors Guest_NumberNotFound 19 — 4y
0
Thanks, this seems to have worked, but how would I learn to do stuff like this on my own? I know how tables work and etc but I still couldn't come up with this on my own Guest_NumberNotFound 19 — 4y
Ad

Answer this question