Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.