Script not running with no errors

my script wont run despite no errors does anyone know whats wrong

while true do
	if script.Parent.Health.Value <= 100 and script.Parent.Health.Value >= 0 then
		print("regening")
		script.Parent.Health.Value = script.Parent.Health.Value + 1
		wait(0.5)
	end
	print("did regen?")
	wait()
end

Where Does It Run?
Local Script Or Script?

1 Like

script inside the player in game.Players

i dont undertand why it would not work though, in fact it dosent seem to run at all even if i put a print before anything

heres the thing though, this is not inflicting upon player health, it is affecting custom health i have added on the player as a int value

i sort of wanna make this death system that teleports the player instead of actually killing them

i just said, this is not about humanoid health, rather custom health as an int value on the player

Instead of using a while loop, try using the .Changed event. It’s an event of IntValue. It will fire whenever the IntValue changes its value.

More information can be found here:
https://developer.roblox.com/en-us/api-reference/event/IntValue/Changed

Also, are you showing us the entire script? Or is this just a snippet?

but my question is why it would not work to begin with, the script seems just fine and would work the same way with the changed event

and also fyi, the script is cloned from another script then parented to the player, but i dont think that will help with anything

There doesn’t seem to be anything wrong with your code; however I do notice that the health Value (when not regenerating) will be at 101 and the value will regenerate even when it’s 0 (though, as you implied, that might be intended since you’re making your own custom-type health system).

When you clone the script from another script, are you changing the script.Disabled property? The template script should be disabled, but when you clone it to the player, it should be enabled.

yes but i think i had this problem before and some guy told me its because you cant say one value is equal and less than this number and greater and equal to this other number because that would not make sense

I don’t know the context in which your previous problem occurred, but I can tell you that the conditional you wrote in this scenario makes 100% sense. The code in the if statement fires when the value is between 0 and 100 (inclusive). I see nothing wrong with that.

well you can take a look at this topic but i cant put the same problem solution together with this one because it wont work
https://devforum.roblox.com/t/script-not-running-despite-no-errors/1555275

well i this point i remade the script to be something simpler and guranteed to work but it still refuses to work for some reason, which could lead me to think, do scripts even work in the player instance?

That’s different. You were checking to see if the ClockTime was less than a low number but ALSO greater than a higher number, which makes no sense. Here you’re checking to see if the value is lower than a HIGH number and greater than a LOW number, which does make sense.

Can I see the script that clones this script into the player along with the explorer window?

Yes, scripts do work in the player instance.

but heres the script

while true do
	if script.Parent.SubHealth.Value <= 100 then
		script.Parent.SubHealth.Value = script.Parent.SubHealth.Value + 1
		wait(0.5)
	end
	wait()
end

it still refuses to work for some reason despite no error
i changed the name of the custom health btw

Can I see the script that clones this script into the player along with the explorer window?

how do you take a snap of the window