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

How do i make it so i can hit multiple people at once?

Asked by 4 years ago

Hi, i'm making a magic type game, and i need help.

local hitS = false



if hitS == false then
local allie1 = game.Players[player.Name].PlayerGui.Allie1
local allie2 = game.Players[player.Name].PlayerGui.Allie2
local allie3 = game.Players[player.Name].PlayerGui.Allie3
hitS = true
local hum = hit.Parent:FindFirstChild("Humanoid")
hum:TakeDamage(45)

This is not the whole script but its the damage portion, i want to make it so i can hit multiple people , but if i remove hitS then i keeps doing 45 damage to everyone in the hitbox area. I want to make it so if there is 3 people in the hitbox area it does just 45 damage to everyone.

0
Can you show us where the "hit" variable comes from? gskw 1046 — 4y
0
From a .Touched Function Real_BoomyBoomYT 10 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago

Hi.

I believe an easy way to do this is to just set several variables that state how much health each person will be deducted on hit. Otherwise, it gets complicated.

Hope this helps.

0
if i remove the hitS value the player gets delt 45 damage over and over again, so i use seperate variables it would do the same? Also each players is supposed to get delt 45. I may have not understood what you mean by multiple variables, please explain. Real_BoomyBoomYT 10 — 4y
0
@Real_BoomyBoomYT You will set up several variables that are specific for the player. Example: CheeseRespect2019 -2 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

you magic is an object in workspace, maybe mostly transparent, but still one stand alone object in workspace cloned everytime you initiate a new majic until it is destroyed. keep the lifespan of this object in your mind.

now, here is the important part, the script can have variables outside function, and that variable stay valid as long as the script is not destroyed.

so you need to create a "memory" in the script, when it hit someone, it marks down who it hits, and remember all of them to this point. and before you plan to hit another one, check if the new guy has been hit in its memory.

done.

0
But the script is not destroyed when the magic is destroyed since the script is in serverscriptservice, but i will try something simillar Real_BoomyBoomYT 10 — 4y
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

The way I do this is by using the .Touched function and values. Say you are doing a fireball. When the fireball is touched I have it check the player's name, generally by finding their character model and using it's name, then by checking the fireball for their name. Example:

fireball.Touched:Connect(function(hit)
    local hitPlayer = nil
    if hit.Parent:FindFirstChild("Humanoid") then
        hitPlayer = hit.Parent
    else if hit.Parent.Parent:FindFirstChild("Humanoid") then
        hitPlayer = hit.Parent.Parent
        end
    end

    if hitPlayer ~= nil
        if fireball:FindFirstChild(hitPlayer.Name) then
            return
        else
            local playerTag = Instance.new("StringValue", fireball)
            playerTag.Name = hitPlayer.Name
            game.Debris:AddItem(playerTag, 1)
            hitPlayer.Humanoid.Health = hitPlayer.Humanoid.Health - 25
        end
    end
end)

This way every time they're hit it'll check if their tag is there and if it finds it, it won't hit them again. If not, it'll add their tag then damage them. The Debris line is there to remove the tag after some time for things like AoE style of attacks so if the player is still touching it, it'll hit them again and readd their tag.

This is just the method I use and there are definitely much tidier means of doing so but this is the method I found that works for me.

Answer this question