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

Why wont this kill ALL the players?

this is my first attempt at for i,v in pairs() do so i got no idea what im doing wrong and i get no errors from this this is my local script

    local player = game.Players.LocalPlayer
    
        player.Chatted:Connect(function(msg)

if msg:lower() == "kill all" then

for i,v in pairs(game:GetService("Players"):GetChildren()) do

if v.ClassName == "Player" then

local players = v

game:GetService("ReplicatedStorage"):WaitForChild("killall"):FireServer(players)

end

end

end

end)

btw i have the msg function already and this is my server script

game.ReplicatedStorage:WaitForChild("killall").OnServerEvent:Connect(function(players)

players.Character.Humanoid.Health = 0

end)

3 comments

0

btw when this is being used it only kills the player who said it

0

Not sure how much of a difference this would make, but try changing "v.ClassName == "Player"" to "v:IsA("Player")"

0

didnt work sadly, still has the same effect

1 answer

The OnServerEvent's first parameter is the PlayerObject who fired the remote.

--Local Script
local arg1 = game.Players.Player
local arg2 = 'hi'
RemoteEvent:FireServer(arg1, arg2)

--Server Script
RemoteEvent.OnServerEvent:Connect(function(player, arg1, arg2)
    local player_who_FireServer = player
    local player_I_want_to_kill = arg1
    print(arg2)
end)

Output: hi

Note: I named the variables similar for explanation purpose.

7 comments

0

this stopped me from finding the humanoid

3

I'm explaining to you how RemoteEvents work because you are using them wrong. I'm not writing the script for you.

0

He made it pretty clear code-wise on how to adapt this to your needs, I do admit he could've added some text explanation, but that's what https://developer.roblox.com/articles/Remote-Functions-and-Events this is for. Other than that he answered your question just fine.

2

Also, Phantom, nice job on getting 100 rep in a day. Just don't go too fast or people might accuse you of botting or something, it happened to me :)

1

Also downvoting isn't there because you don't like the answer you were given, it's there because the answer that was given not only doesn't answer the question, but also shows bad coding practices. None of which are in the code provided in this answer.

0

im accepting tis answe scuz eveyrthing here iscuhfdj mfjerfkvaeri

0

lovely ^

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