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

respawn all players if one dies?

Asked by 2 years ago

Hello all,

I was wondering if anyone knows how to make it so if one player dies, all players die.

Thanks

0
As in any random player or a surtent player? PufferfishDev 49 — 2y
0
Yeah, if any player dies in the server. Helloimpets 17 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Hello Helloimpets,

My name is The_Pumpkin President (formerly ZakOMGmcpe564) and I'd be happy to help you with your problem.

You're going to want to insert a couple things:

  • A remote event in Replicated Storage
  • A localscript in StarterGUI
  • A serverscript in ServerScriptStorage

Call the remote event "KillEvent." In said localscript, type in this code.

local plr = game.Players.LocalPlayer
local humanoid = plr.Character.Humanoid

humanoid.Died:Connect(function() -- When the player dies. This applies to everyone in the server.
 game.ReplicatedStorage.KillEvent:FireServer()
end)

Then, in the server script you put in ServerScriptStorage, type this code:

game.Replicated.OnServerEvent:Connect(function()
 local plrs = game.Players:GetChildren() - This gets all the players currently in the game.
 for i = 1,#plrs do
   plrs[i]:LoadCharacter() -- Loads the player's characters. They will generally spawn on SpawnLocations, althouigh if there is none they will spawn at X: 0, Z:0.
 end
end)

Please reply to this answer is you're facing any issues.

Hope this helps!

0
Thank you very much, you wouldnt happen to know how to implement it so it tells you who killed the person. If not, dont worry about it. Again, thank you alot! Helloimpets 17 — 2y
0
I think I might, but it'll have to wait a little bit as I'm a bit busy ATM. And you're very welcome and I wish your game the best! ZakOMGmcpe564 52 — 2y
Ad

Answer this question