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

Help with : "onDeath,Ect."?

Asked by
iLegitus 130
9 years ago

I need some tips or links for the best way to do :

If i have the entire server teleported,But one is picked randomly by a function,I want him to NOT count with the people who got teleported. Basically,When this "randomPlayer" kills the rest of the players who got teleported i want something to happend(Ill script that),But any tips,Help ect?

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

This is NOT a request site. Please include any coding you have already done.

Anyways, to get a random player we can just use table[index]. Since the GetPlayers() method returns a table of all the players in the game, this will work. To get the actual random number, we use math.random(), and the # sign to make sure that number is in between 1 and the number of players in the game.

local players = game.Players:GetPlayers()
local randomPlayer = players[math.random(1,#players)]
print(randomPlayer.Name)

To detect when a player dies, we need to use the Died event. To connect this event to all players, we just look through Players with a for loop. Then, since we want to ignore the random player, check if the current player equals the random player, and if it doesn't, connect it to the event.

for i,v in pairs(game.Players:GetPlayers()) do
    if v ~= randomPlayer and v.Character then
        v.Character.Humanoid.Died:connect(function()
            print(v.Name.."died!")
        end)
    end
end
0
What the? Are you blind? Look at my question it clearly said ANY TIPS and best way to do it. Wow. I didnt ask for coding. iLegitus 130 — 9y
0
I appriciate the coding youve done but I didnt request it as you said : "This is not a request site". iLegitus 130 — 9y
0
Read this. You violate points 2, 3, and 4. https://scriptinghelpers.org/help/how-post-good-questions-answers Perci1 4988 — 9y
Ad

Answer this question