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

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

Asked by 7 years ago
Edited 7 years ago

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

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. TheeDeathCaster 2368 — 7y
0
Thanks! TherDanTDM 24 — 7y
0
Np. TheeDeathCaster 2368 — 7y

1 answer

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
7 years ago
Edited 7 years ago

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)
0
Thanks lol i know im new to lua and i thought it would work xD TherDanTDM 24 — 7y
0
If this is correct, I'll appreciate if you accept the answer :) cabbler 1942 — 7y
0
Unfortunately this script doesn't work the npc dies but me (In team yellow) don't die ;-; TherDanTDM 24 — 7y
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) TherDanTDM 24 — 7y
View all comments (6 more)
0
You might have to wait for Humanoid to load. I'll edit this accordingly. cabbler 1942 — 7y
0
okay TherDanTDM 24 — 7y
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 TherDanTDM 24 — 7y
0
The script has to be parented to the Humanoid's parent, and not a LocalScript. cabbler 1942 — 7y
0
script is in the npc and not a localscript but still not working TherDanTDM 24 — 7y
0
Okay the script is fine, it's not my problem you can't get it to work in context. cabbler 1942 — 7y
Ad

Answer this question