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

On touch Poison script is not working for some reason and I don't know how to fix it?

I have been trying to get my poison script to work but it just won't. I have been on the roblox wiki looking for an anwser but i can't find anything.

Her is my script

	local dmg = -10

	function onTouched(part)
	local humanoid = part.Parent:FindFirstChild("Humanoid")
	if (humanoid ~= nil) then
		while true do
		local currenthealth = humanoid.Health
		local NewHealth = currenthealth + dmg
		humanoid.Health = currenthealth
		wait(1)
		if humanoid.Health == 50 then
			break
		end
			wait()
		end
		end
	end
	
	script.Parent.Touched:connect(onTouched)
	wait()

I am very new to scripting so my script is probably really bad!

3 answers

✓ Accepted answer

Again. Just like ruflixx's code. DO NOT USE WHILE WAIT() DO. Thanks!

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
	local debounce = false
        while hit.Parent.Humanoid.Health > 0 do
	    wait(1)
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 10
        end
    end
end)

1 comment

0

Thank you!

Try this, hope it helps!



script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		while wait() do
			hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 10
		end
	end
end)


1 comment

0

I should of said it in the post that I want the player to take damage every second and you don't have to be standing on the brick.

Simillar to Ruflixx's code, but use repeat so it won't loop even after they have died.

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') then
		repeat
			hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 10
			wait(3) -- So it doesnt do it almost instantly
		until hit.Parent.Humanoid.Health <= 0
	end
end)

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