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

How would I change It so It also damages NPCS and the other team?

Asked by 2 years ago
Edited 2 years ago

So I used this

script.Parent.Touched:Connect(function(hit)
    local character = hit.Parent
    local player = game.Players:GetPlayerFromCharacter(character)
    if player then
        if player.Team.Name ~= script.Team.Value then
            character.Humanoid.Health = character.Humanoid.Health -math.random(50,100)
        end
    end
end)

And It damages the players on the other team but not NPC'S, how can I change It so NPC's can be damage as well of enemies on the other team? (NOTE: AN STRINGE VALUE IS INSIDE OF THE SCRIPT)

1 answer

Log in to vote
0
Answered by
SuperPuiu 497 Moderation Voter
2 years ago
Edited 2 years ago

Should work: (Im on mobile)

script.Parent.Touched:Connect(function(hit) 
local character = hit.Parent 
local player = game.Players:GetPlayerFromCharacter(hit)
if player then 
if player.Team.Name ~= script.Team.Value then 
character.Humanoid.Health = character.Humanoid.Health -math.random(50,100) 
end 
else -- if it isnt a player then
if hit.Parent:FindFirstChild("humanoid") then
character.Humanoid.Health = character.Humanoid.Health -math.random(50,100) 
end
end 
end
end)
Ad

Answer this question