Gate isn't regenerating

Hello there,

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

image

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)

Parts can’t die, can they? Make sure script.Parent is a Humanoid, not a Part.

1 Like

Would I do

script.Parent.Humanoid.Died:connect(function()
   wait(3)
   regen()
end)

If Humanoid was a child of script.Parent, yes.

1 Like

image

That’s what I did and for some reason it’s not taking any damage.

Humanoids work best in models like so:

  • Model
    • Head
    • Humanoid

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.

1 Like

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?

no it aint. There’s no code for instant healing in your code.

1 Like

I have another script in it:

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.

How are you dealing damage? You need to modify the Humanoid’s health property, not custom values if that’s what you were doing.

You can do it a couple of ways:

Humanoid:TakeDamage(Amount)
-- OR
Humanoid.Health = Humanoid.Health - Amount
2 Likes

Yeah I was using a value. The Humanoid’s health is set to 100. How would I define Humanoid in a script?

Same way you define objects.

local RandomHumanoid = workspace.Model.Humanoid

3 Likes

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.

1 Like

Yeah that’s what I was trying to do, use the values. Me and my scripter are currently working on this issue with the sword.