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
...