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

How do i damage every player using a script?

Asked by 3 years ago

I've been trying to figure out how to damage every player, I searched for solutions on google and none of them worked, Here is what I got so far.

game.Workspace.i.Touched:Connect(function(hit)
    print("Touched")
    if hit.Parent:FindFirstChild("Humanoid") then
        print("Found a Character!")
        if hit.Parent:FindFirstChild("pathfinding") then
            print("Its an enemy!")
            hit.Parent:Destroy()
            print("they died now")
               --here is the part where it damages every player
                print("damaged player")
                end
        end
    end)

What happens In this script is when an enemy touches a part that its walking to using a script and then uses the same script to detect if its an NPC since the player does not have that script inside them it then deletes the NPC after it touches it and damages every player at the server

You can tell its a defense game.

1 answer

Log in to vote
0
Answered by 3 years ago

I think you can use a for loop to get all the players in the game, then find the humanoid of each player, something like this:

for i,v in pairs(game.Players:GetChildren())do
     local player = game.Workspace:FindFirstChild(v.Name)
     if player.Humanoid then -- making sure that it is actually a player
           player.Humanoid.Health = player.Humanoid.Health-10 -- put this to whatever you want
     end
end

I hope this has been of help, if so, please accept this answer :)

Ad

Answer this question