local shouldRun = true
local player = game:GetService("Players").LocalPlayer
-- Function to detect character death
local function setupDeathListener(character)
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.Died:Connect(function()
shouldRun = false
end)
end
end
-- Initial listener
if player.Character then
setupDeathListener(player.Character)
end
-- Listen for character respawn
player.CharacterAdded:Connect(function(character)
if not shouldRun then return end
setupDeathListener(character)
end)
-- Main loop
while shouldRun do
local character = player.Character
if not character then wait(0.1) continue end
local rootPart = character:FindFirstChild("HumanoidRootPart")
if not rootPart then wait(0.1) continue end
local backpack = player:FindFirstChild("Backpack")
if not backpack then wait(0.1) continue end
local btools = backpack:FindFirstChild("Btools")
if not btools then wait(0.1) continue end
local syncAPI = btools:FindFirstChild("SyncAPI")
if not syncAPI then wait(0.1) continue end
local serverEndpoint = syncAPI:FindFirstChild("ServerEndpoint")
if not serverEndpoint then wait(0.1) continue end
for _, otherPlayer in pairs(game:GetService("Players"):GetPlayers()) do
if otherPlayer ~= player and otherPlayer.Character then
local otherRoot = otherPlayer.Character:FindFirstChild("HumanoidRootPart")
if otherRoot and (otherRoot.Position - rootPart.Position).Magnitude <= 20 then
local targetTorso = otherPlayer.Character:FindFirstChild("Torso") or otherPlayer.Character:FindFirstChild("UpperTorso")
if targetTorso then
local args = {
"Remove",
{
targetTorso
}
}
serverEndpoint:InvokeServer(unpack(args))
end
end
end
end
wait(0.1)
end
Comments
No comments yet
Be the first to share your thoughts!