Poison Script Not Working

I am making a script for poisoning mobs in game.

Here is the script:

Summary
local mob = script.Parent
local poison = mob:WaitForChild("Poison")

if poison.Changed then
	wait(1)
	if poison.Value == true then
		while true do 
			mob.Humanoid:TakeDamage(25)
			print("HES GASSED")
			task.wait(1.5)
		end
		
	else
		print("WHY IT CHANGE THEN")
	end
end

I have an addition script for targeting that sets the Value to true, which works fine.

The target will take initial damage from the targeting script, Value is True, and then I see the WHY IT CHANGE print function after.

I’ve checked both client and server side, the Value IS set to true, but the poison script always says that it is false.

I’ve added waits and it does not help, am I doing it wrong using Changed or what is the issue?

Wouldn’t use use

poison.Changed:Connect(function()
    wait(1)
	if poison.Value == true then
		while true do 
			mob.Humanoid:TakeDamage(25)
			print("HES GASSED")
			task.wait(1.5)
		end
		
	else
		print("WHY IT CHANGE THEN")
	end
end)

Instead? Because I don’t think that poison.Changed would work because that is an event for when the value changes so you can’t really check it with an if statement.

1 Like
local mob = script.Parent
local poison = mob:WaitForChild("Poison")


while true do 
	if poison.Value == true then
		while true do 
			mob.Humanoid:TakeDamage(25)
			task.wait(1.5)
		end
	else
	end
	task.wait(1.5)
end

This is the updated script that works perfectly

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