narratorxd

Scp roleplay head and body hitbox

Aug 3rd, 2024 (edited)
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.87 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2.  
  3. -- Define team groups
  4. local classDAndChaosInsurgency = { "Class - D", "Chaos Insurgency" }
  5. local otherTeams = { "Security Department", "Mobile Task Force", "Internal Security Department", "Administrative Department", "Intelligence Agency", "Rapid Response Team", "Scientific Department", "Medical Department" }
  6.  
  7. local resizedParts = {} -- Track resized parts
  8.  
  9. -- Function to check if a player's team is an enemy team
  10. local function isOnEnemyTeam(targetPlayer)
  11.     if targetPlayer.Team then
  12.         local playerTeam = player.Team and player.Team.Name
  13.         local targetTeam = targetPlayer.Team.Name
  14.  
  15.         if table.find(classDAndChaosInsurgency, playerTeam) then
  16.             return table.find(otherTeams, targetTeam) ~= nil
  17.         else
  18.             return table.find(classDAndChaosInsurgency, targetTeam) ~= nil
  19.         end
  20.     end
  21.     return false
  22. end
  23.  
  24. -- Function to resize head and body parts, and set color to match player's skin tone
  25. local function resizeCharacter(character, headSize, bodySize)
  26.     local head = character:FindFirstChild("Head")
  27.     local torso = character:FindFirstChild("Torso") or character:FindFirstChild("UpperTorso") or character:FindFirstChild("LowerTorso")
  28.    
  29.     if head then
  30.         -- Save original properties
  31.         if not resizedParts[character] then
  32.             resizedParts[character] = {
  33.                 head = head,
  34.                 torso = torso,
  35.                 originalHeadSize = head.Size,
  36.                 originalHeadTransparency = head.Transparency,
  37.                 originalHeadMaterial = head.Material,
  38.                 originalHeadCanCollide = head.CanCollide,
  39.                 originalTorsoSize = torso and torso:IsA("Part") and torso.Size or nil,
  40.                 originalTorsoTransparency = torso and torso:IsA("Part") and torso.Transparency or nil,
  41.                 originalTorsoMaterial = torso and torso:IsA("Part") and torso.Material or nil,
  42.                 originalTorsoCanCollide = torso and torso:IsA("Part") and torso.CanCollide or nil
  43.             }
  44.         end
  45.  
  46.         -- Find the player's skin tone (assuming "Left Arm" has the correct skin color)
  47.         local leftArm = character:FindFirstChild("Left Arm") or character:FindFirstChild("LeftUpperArm")
  48.         if leftArm then
  49.             head.BrickColor = leftArm.BrickColor
  50.         else
  51.             head.BrickColor = BrickColor.new("Really white") -- Default if skin tone cannot be found
  52.         end
  53.  
  54.         -- Resize head
  55.         head.Size = Vector3.new(headSize, headSize, headSize)
  56.         head.Transparency = 1.0 -- Make head fully opaque
  57.         head.Material = "Neon"
  58.         head.CanCollide = false
  59.  
  60.         -- Resize torso
  61.         if torso and torso:IsA("Part") then
  62.             torso.Size = Vector3.new(bodySize, bodySize, bodySize)
  63.             torso.Transparency = 0.5 -- Example transparency for torso
  64.             torso.Material = "Neon"
  65.             torso.CanCollide = false
  66.         end
  67.     end
  68. end
  69.  
  70. -- Function to handle character addition for enemies
  71. local function onCharacterAdded(character)
  72.     local headSize = 3 -- Resize head size to 3
  73.     local bodySize = 6 -- Resize body size to 6
  74.     resizeCharacter(character, headSize, bodySize)
  75. end
  76.  
  77. -- Function to handle player addition for enemies
  78. local function onPlayerAdded(enemyPlayer)
  79.     enemyPlayer.CharacterAdded:Connect(function(character)
  80.         onCharacterAdded(character)
  81.     end)
  82.     -- If the player already has a character, resize the head and body immediately
  83.     if enemyPlayer.Character then
  84.         onCharacterAdded(enemyPlayer.Character)
  85.     end
  86. end
  87.  
  88. -- Function to update enemies when the player's team changes
  89. local function updateEnemies()
  90.     -- Restore original properties for all players
  91.     for character, tracked in pairs(resizedParts) do
  92.         if tracked.head then
  93.             tracked.head.Size = tracked.originalHeadSize
  94.             tracked.head.Transparency = tracked.originalHeadTransparency
  95.             tracked.head.Material = tracked.originalHeadMaterial
  96.             tracked.head.CanCollide = tracked.originalHeadCanCollide
  97.         end
  98.         if tracked.torso and tracked.originalTorsoSize then
  99.             tracked.torso.Size = tracked.originalTorsoSize
  100.             tracked.torso.Transparency = tracked.originalTorsoTransparency
  101.             tracked.torso.Material = tracked.originalTorsoMaterial
  102.             tracked.torso.CanCollide = tracked.originalTorsoCanCollide
  103.         end
  104.     end
  105.     resizedParts = {}
  106.  
  107.     -- Resize heads and bodies for current enemies
  108.     for _, v in ipairs(game:GetService('Players'):GetPlayers()) do
  109.         if v ~= player and isOnEnemyTeam(v) then
  110.             onPlayerAdded(v)
  111.         end
  112.     end
  113. end
  114.  
  115. -- Initial update of enemies
  116. updateEnemies()
  117.  
  118. -- Update enemies if the local player's team changes
  119. player:GetPropertyChangedSignal("Team"):Connect(updateEnemies)
  120.  
  121. -- Connect the player added event
  122. game:GetService('Players').PlayerAdded:Connect(function(newPlayer)
  123.     if newPlayer ~= player and isOnEnemyTeam(newPlayer) then
  124.         onPlayerAdded(newPlayer)
  125.     end
  126. end)
  127.  
  128. -- Function to repeatedly resize heads and bodies of enemies every second
  129. local function autoResizeCharacters()
  130.     while true do
  131.         wait(1) -- Wait for 1 second
  132.         for _, v in ipairs(game:GetService('Players'):GetPlayers()) do
  133.             if v ~= player and isOnEnemyTeam(v) then
  134.                 pcall(function()
  135.                     local character = v.Character
  136.                     if character then
  137.                         local headSize = 3 -- Resize head size to 3
  138.                         local bodySize = 6 -- Resize body size to 6
  139.                         resizeCharacter(character, headSize, bodySize)
  140.                     end
  141.                 end)
  142.             end
  143.         end
  144.     end
  145. end
  146.  
  147. -- Start a new thread to auto-resize heads and bodies of enemies
  148. coroutine.wrap(autoResizeCharacters)()
Advertisement
Add Comment
Please, Sign In to add comment