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

Npc can find other team but cant do damage?

The script is inside of the npc. the npc is cloned in through a button, giving the npc a string value of the player who cloned the npc's team (player1 is on purple team, player1 clicks button and npc is cloned in, a string value is added with the value of "purple") . The npcs have follow scripts with target npcs of different teams. problem is the damage script either can't find the opposing npc's humanoid or another problem i don't know about

function dmg(hit)
	if hit ~= nil then
		local npcTeam = script.Parent.Team.Value
		local enemyTeam = hit.Parent.Team.Value
		local enemyHuman = hit.Parent:FindFirstChildOfClass("Humanoid")
		if npcTeam ~= enemyTeam then
			enemyHuman.Health = enemyHuman.Health - 10
		end
			
		
	end
end

hitbox.Touched:Connect(dmg)

1 answer

Try this:

hitbox.Touched:connect(function(hit)
	local hum = hit.Parent:FindFirstChild('Humanoid')
	if hum ~= nil then
		local npcTeam = script.Parent.Team.Value
		local enemyTeam = hit.Parent.Team.Value
		if npcTeam ~= enemyTeam then
			hum:TakeDamage(10)
		end
	end
end)

I didn't test this out, so I have no idea if it would work but if it doesn't tell me any output errors if there are

1 comment

0

no error, but no damage is being done

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