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.
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.
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.
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.