Script Not Working

Okay so basically I am trying to fire an event to the server once the player’s health reaches zero and the script that responds to the event being fired to the server is supposed to do things bassed on a value within a folder found inside of the player but for some reason the script I used isn’t working at all and I didn’t get anything in output and I even added a print message to see if it was fired successfully but it did not work.

This is the code;

(the script is a server script within the character, i changed it from module and changed it up because it wasn’t working before either so i don’t know)

while true do
	script.Parent.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
	wait()
end

local Character = script.Parent

Character:FindFirstChild("Humanoid"):GetPropertyChangedSignal("Health"):Connect(function()
	if Character.Humanoid.Health <= 0 then
		game:GetService("ReplicatedStorage").Events.HandlerEvent:FireServer("PlayerDied")
		print("The event has been successfully fired to the server!")
	else
		print("The event could not be fired to the server.")
	end
end)

Your script is not working because you have an infinite while loop. Any code after the while loop is not going to run.

1 Like

You should move the while loop to the end of the script, as the above reply said like this:

local Character = script.Parent

Character:FindFirstChild("Humanoid"):GetPropertyChangedSignal("Health"):Connect(function()
	if Character.Humanoid.Health <= 0 then
		game:GetService("ReplicatedStorage").Events.HandlerEvent:FireServer("PlayerDied")
		print("The event has been successfully fired to the server!")
	else
		print("The event could not be fired to the server.")
	end
end)

while true do
	wait()
	Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
end
2 Likes

Thanks I completely forgot the loop being above it all!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.