Script not doing what it's told?

We need to see your new code, please. If you used math.min and never changed MaxHealth, this should not happen.

local db = false
script.Parent.Touched:Connect(function(part)
	
	local humanoid
	 
	if part.Parent.Humanoid then
	humanoid = part.Parent.Humanoid
	elseif part.Parent.Parent.Humanoid then
	humanoid = part.Parent.Parent.Humanoid
	end
	if humanoid ~= nil and db == false then
		db = true
		humanoid.Health = math.min(humanoid.Health + 50, humanoid.MaxHealth)
		script.Parent.Parent:Destroy()
		wait(1)
		db = false
	end
end)

Iā€™ve also tried to do it like this as well

Other code
local db = false
script.Parent.Touched:Connect(function(part)
	
	local humanoid
	 
	if part.Parent.Humanoid then
	humanoid = part.Parent.Humanoid
	elseif part.Parent.Parent.Humanoid then
	humanoid = part.Parent.Parent.Humanoid
	end
	if humanoid ~= nil and db == false then
		db = true
		if humanoid.Health <= 99 then
		humanoid.Health = math.min(humanoid.Health + 50, humanoid.MaxHealth)
		script.Parent.Parent:Destroy()
		end
		wait(1)
		db = false
	end
end)

Of course I donā€™t think this would do that much.

Also hereā€™s a visual demonstration.

Are you absolutely positive you applied the script changes?
Are there any other scripts in your game that also affect the humanoidā€™s health?

This is just a plain baseplate. This also isnā€™t in team create so Iā€™m pretty sure you donā€™t have to apply changes with a said ā€œbuttonā€ I guess

I tried the script in an empty game with a dummy part and it works perfectly, with the exception of the line script.Parent.Parent:Destroy(), but you probably used that to destroy the parent model.
Bottom line is the script works by itself, so the problem is somewhere else.

Iā€™ll give it a try in another game, just in case if thereā€™s a random script somewhere I canā€™t see for some reason.

1 Like

Yeah, I tested it in a clean test server, no extra scripts or anything. It did the same thing. I also tested this with just one health pad and not using 2 and set my health to something like 70 and it still resulted in the same thing.

This is my test game:
heal_brick.rbxl (18.5 KB)
I used the exact same script.

yeah this worked, super odd, I even put it into my actual model and it still works. I really donā€™t know what was wrong.

Maybe the script changes were not applied, or were not duplicated across the models. Does it work now?

It does work now. very odd.

30

1 Like