I just encountered one of the weirdest things while working on a CreatureHandler module.
Below is the code for a function that creates a new creature. My goal is to make it so once the creature dies, the model gets destroyed. Even though I’m calling :Destroy(), the model isn’t destroying itself. I thought this was weird so I did some investigating.
I found that if I print before and after the Destroy() (as shown below), it prints the following:
Another weird thing I noticed is that if I print CreatureHandler.creature.Parent.Name after I call destroy, the parent is nil.
Apparently calling Destroy() is setting CreatureHandler.creature to “Spider”, instead of destroying the actual instance object inside of workspace.
This is a module script.
function CreatureHandler.new(creaturetype, spawnpart)
if spawnpart then
CreatureHandler.SpawnPart = spawnpart
end
CreatureHandler.creature = CreatureStorage:FindFirstChild(creaturetype):Clone()
CreatureHandler.creaturemodule = require(game.ServerStorage.CreatureModules[creaturetype])
createMovers()
CreatureHandler.creature.Parent = workspace.Creatures
CreatureHandler.creature.Humanoid.Died:Connect(function()
print"DIEDDDDDDDDD"
--if RotationConnection then
--RotationConnection:Disconnect()
--end
print(CreatureHandler.creature.Parent.Name.." is the parent before")
CreatureHandler.creature:Destroy()
print(CreatureHandler.creature)
--print(CreatureHandler.creature.Parent.Name.." is the parent after")
spawn(function()
print"REEEESPAWWNNN"
CreatureHandler:RespawnCreature()
end)
CreatureHandler:RewardPlayers()
print(CreatureHandler.creature.Name.." IS THE ANME OF THE CREATURE")
end)
end
I have also tried destroying parts inside of the spider by doing CreatureHandler.creature.HumanoidRootPart:Destroy() but it doesn’t destroy anything.
Does anyone know why this is happening, and also how I would be able to destroy the actual spider model in workspace?
It almost seems like this is a bug and it shouldn’t work this way.