Hello, I Need help making the players can eat eachothers based on their torso size, Like Agar.io
so i made a hitbox script to be inside the player’s torso, but i need help making the players only can kill/eat eachothers based on their torso size,
Hitbox Script
– Script in ServerScriptService
local Players = game:GetService(“Players”)
– Function to disable collision for character parts
local function disableCollision(character)
for _, part in pairs(character:GetChildren()) do
if part:IsA(“BasePart”) then
part.CanCollide = false
end
end
end
– Function to get the size of the player’s torso
local function getTorsoSize(player)
local character = player.Character
if character then
local torso = character:FindFirstChild(“Torso”) or character:FindFirstChild(“UpperTorso”)
if torso then
return torso.Size.Magnitude
end
end
return 0 – Return 0 if no torso is found
end
– Function to create the kill part
local function createKillPart(player)
local character = player.Character
if character then
local torso = character:FindFirstChild(“Torso”) or character:FindFirstChild(“UpperTorso”)
if torso then
– Disable collision for character parts
disableCollision(character)
-- Create a new part
local killPart = Instance.new("Part")
killPart.Size = Vector3.new(1, 1, 1) -- Set the size of the part
killPart.Transparency = 1 -- Make the part invisible (optional)
killPart.CanCollide = false -- Disable collision (optional)
killPart.Anchored = false -- Allow the part to move with the player
killPart.Name = "KillPart"
-- Parent the part to the character
killPart.Parent = character
-- Position the part inside the torso
killPart.Position = torso.Position
-- Weld the part to the torso to move with it
local weld = Instance.new("WeldConstraint")
weld.Part0 = torso
weld.Part1 = killPart
weld.Parent = torso
-- Connect a Touched event to the killPart
killPart.Touched:Connect(function(hit)
local otherPlayer = Players:GetPlayerFromCharacter(hit.Parent)
if otherPlayer and otherPlayer ~= player then
local playerTorsoSize = getTorsoSize(player)
local otherPlayerTorsoSize = getTorsoSize(otherPlayer)
-- Check if the player's torso size is greater than the other player's torso size
if playerTorsoSize > otherPlayerTorsoSize then
-- "Eat" the other player by setting their health to 0
local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
end
end)
end
end
end
– Connect the PlayerAdded event to spawn the kill part and disable collision
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
createKillPart(player)
end)
end)