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

How do i make a npc when the npc dies the team yellow die?

I'm new to scripting (lua) and im making a Defend the point game and i want to know what's wrong in this script so when the point (its an npc) dies all players of team Yellow should die


function die()
	if script.Parent.Humanoid.Health = 0
	then game.Teams.Yellow.Players.Character.Humanoid.Health = 0
end

3 comments

0

Well, you would use, as you have, a function that'll have a for loop, which will loop through the player's service, and if the NPC has "died," then it will execute the "death" function for players: I suggest a variable to accomplish all of this.

0

Thanks!

0

Np.

1 answer

You should use the .Died event of humanoids, which will trigger a function when the npc dies. You have to "connect" it to a function. Info on events / connections

Also, "game.Teams.Yellow.Players" does not make any sense, as "Players" is not a property of a team. However there is a function :GetPlayers() which will do this. It gives you a list of players, so you have to kill each player in the list using a loop. Unfortunately your simplicity does not work lol. Info on Generic for loops

function die()
	--"pairs" loops through this table
	for _,player in pairs(game.Teams.Yellow:GetPlayers()) do
		--safety check
		if player.Character then
			--easy way to kill
			player.Character:BreakJoints()
		end
	end
end

--connect npc death to your function
script.Parent:WaitForChild('Humanoid').Died:connect(die)

10 comments

0

Thanks lol i know im new to lua and i thought it would work xD

0

If this is correct, I'll appreciate if you accept the answer :)

0

Unfortunately this script doesn't work the npc dies but me (In team yellow) don't die ;-;

0

Wait a second cabbler is that you? the legandary football game maker? anyway the script didn't work i didn't die when the npc died (i was in team yellow)

0

You might have to wait for Humanoid to load. I'll edit this accordingly.

0

okay

0

still not working ;-; i tried changing the npcs to check if its not working with only one npc but nope its not working with any npcs

0

The script has to be parented to the Humanoid's parent, and not a LocalScript.

0

script is in the npc and not a localscript but still not working

0

Okay the script is fine, it's not my problem you can't get it to work in context.

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