i want that all player get killed if one player touches a part. But i only want that they will get killed one time. So if i touch the part all players get killed one time
local function killEveryone() local allPlayers = game.Players:GetChildren()
for i = 1, #allPlayers do
allPlayers[i].Character.Humanoid.Health = 0
end end
script.Parent.Touched:Connect(killEveryone)
this is my script, but its killing all players everytime. So i cant respawn.
local function killEveryone(TouchedCharacter)
local player = game.Players:GetPlayerFromCharacter(TouchedCharacter.Parent) or game.Players:GetPlayerFromCharacter(TouchedCharacter.Parent.Parent)
if player == nil then return end
local allPlayers = game.Players:GetChildren()
for i = 1, #allPlayers do
allPlayers[i].Character.Humanoid.Health = 0
end
end
script.Parent.Touched:Connect(killEveryone)
The problem is killing all player even if touched part is not human character
You aren’t allowed to asked for Scripts in scripting support, but I can show you an example with explaining it, from which you will basically get all the idea.
local part = script.Parent
local Players = game:GetService("Players") --Define our variables
local Conn
local function killAllPlayers(hit)
local foundPlayer = Players:GetPlayerFromCharacter(hit.Parent) --Check if the hit part's parent is a player character
if foundPlayer then --If character then...
Conn:Disconnect() --Disconnect the connection
local players = Players:GetPlayers() --Get All players in game
for _, player in pairs(players) do --Iterate through all players
player.Character.Humanoid.Health = 0 -- Set health to 0, basically kill them
end
end
end
Conn = part.Touched:Connect(killAllPlayers) --Assign the connection to the `Conn` variable