I’ve been getting an error for my gate. Basically I am trying to make it destructible so when the gate’s health goes down it will break. I have been getting this weird error that I don’t know how to solve. If anyone knows how to fix this please let me know. All help is appreciated
Error
Code
m = script.Parent.Parent
c = m:clone()
function regen()
m:Remove()
c.Parent = game.Workspace
c:MakeJoints()
end
script.Parent.Died:connect(function()
wait(3)
regen()
end)
The head gives the humanoid something to display the model’s name and the humanoid’s health (this is built-in Roblox behavior so you can’t change it).
I haven’t experimented with humanoids outside of models, so they may work differently. With the amount of information I have for this specific context right now, I have no idea what the issue could be.
Also, something I noticed, you should use Object:Destroy() instead of Object:Remove(). Remove is deprecated and doesn’t work properly.
My sword was able to hit it now that I put the Humanoid in a model. But it still doesn’t seem to deal any damage. Is my script not allowing it to damage?
while true do
wait()
cv=cv+((script.Parent.Health.Value-cv)*0.2)
perc=cv/script.Parent.maxHealth.Value
if perc<.01 then
script.Parent.Display.Enabled=false
else
script.Parent.Display.Enabled=true
end
script.Parent.Display.Green.Size=UDim2.new(perc,0,1,0)
script.Parent.Display.Green.BackgroundTransparency=1-perc
if perc<0.0001 then
script.Parent.Transparency=1
script.Parent.CanCollide=false
wait (30)
script.Parent.Display.Green.Size=UDim2.new(perc,0,1,0)
script.Parent.Display.Green.BackgroundTransparency=1-perc
script.Parent.Transparency=0
script.Parent.Health.Value=100
script.Parent.CanCollide=true
else
script.Parent.Transparency=0
script.Parent.CanCollide=true
end
end
That is the one that is supposed to display the current health and damage.
I suggest doing back to using a value because you don’t actually need a humanoid to handle your gate’s health. All you need to do is look up a changed event to it and if the value is less than or equal to zero, then the gate has been destroyed. If there’s an issue with your weapons around this issue, work on a solution to that problem instead of simply trying ways to work around it.