#Part being destroyed from workplace despite not calling Destroy()?

1 messages · Page 1 of 1 (latest)

robust knoll
#

I am having an issue with my respawning function, where the part seems to successfully despawn with no issue, but then at some point instead of being made visible again, it gets removed from the workspace. I will try and include the relevant code as it's too long to post the whole script. Thanks!

...

local function respawn(part)
 
  part.Transparency = 1
  part.CanCollide = false

  local clickDetector = part:FindFirstChild("ClickDetector")
  if clickDetector then
    clickDetector.MaxActivationDistance = 0
  end
  
  local ui = part:FindFirstChild("BillboardGui")
  if ui then
    ui.Enabled = false
  end
  
  task.wait(1)
  
  
  part.Transparency = 0
  part.CanCollide = true

  local clickDetector = part:FindFirstChild("ClickDetector")
  if clickDetector then
    clickDetector.MaxActivationDistance = 32
  end

  local ui = part:FindFirstChild("BillboardGui")
  if ui then
    ui.Enabled = true
  end

  part:SetAttribute("Health", maxHealth)
  isTicking = false
end

local function updateHealthDisplay(part, currentHealth)
...
end

local function onClick(player)
  if isTicking then return end

  local character = player.Character
  local targetBrick = character:FindFirstChild("TargetBrick")
  targetBrick.Value = part


  isTicking = true

  while isTicking do

    local Players = game:GetService("Players")

    if part:GetAttribute("Health") <= 0 then
      isTicking = false

      for _, player in Players:GetPlayers() do
        local character = player.Character
        local targetBrick = ...
        if targetBrick.Value == part then
          targetBrick.Value = nil
        end
      end
      respawn(part)
    end

    for _, player in Players:GetPlayers() do
      local character = player.Character
      local targetBrick = ...
      if targetBrick.Value == part then
        local health = part:GetAttribute("Health")
        part:SetAttribute("Health", health - 1)
      end
    end
    
    updateHealthDisplay(...)

    task.wait(1)
  end
end

...
civic rune
#

youre probably setting the cancollide to false which makes the part immediately fall through the floor. while cancollide gets set to true its already in freefall and deletes itself shortly when hitting the worldlimit