Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why doesn't my script work when the other one does if statement?

So pretty much I have lots more code but it is this part that doesn't work

if humanoid.Health <= 0 then
				print("why")
				local function work(player)
					game.ReplicatedStorage.GiveFear:FireServer()
					print("noob")
					print(humanoid)
					print(humanoid.Health)
				end
				print("work")
				work()
			end

However, it does work when you do this

if humanoid.Health >= 0 then
				print("why")
				local function work(player)
					game.ReplicatedStorage.GiveFear:FireServer()
					print("noob")
					print(humanoid)
					print(humanoid.Health)
				end
				print("work")
				work()
			end

Can someone please explain why and how to fix this.

4 comments

0

There is no difference between the two scripts.

0

oh yeah sry

0

k i changed it

0

I noticed you have a ":FireServer" Do you have script in your remote event? If so then try adding the "print("worked") Statement inside the Remote Event.

1 answer

✓ Accepted answer

when the script is executed it checks if the player is dead before starting that local function so if the player is alive the local function will work, put the if statement in the function that should fix.

2 comments

0

ill try

0

it didn't it only did the function and never got to the if statement

This discussion is preserved as it was. New answers, comments, and votes are closed.