!NEED HELP! I tried to adds script for to stop loop

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I want loop stop on certain touch part or loop will stop on health 0

  2. What is the issue?
    wont stop loop on (and). if I use or then stop for no reason.

  3. What solutions have you tried so far?
    I tried used or on it which working well but if didn’t touch certain part for while then will stops loop of damaging for no reason. Also issued a error called Attempt to connect failed: Passed value is not a function

So I use and and wont working on touch part for to stop damaging. So I searched up on these and non of these fit this problems.

repeat
				hum:TakeDamage(2)
				wait(0.5)
			until hum.Health == 0 or hum.Touched:Connect(waterPart)

(Reminder, I’m beginner scripter and I just show you a part of code not fully bc rest of it is working well except this code that I show you. if you need fully code. lmk so I can show you.)

1 Like

Try …
until hum.Health <= 0 or hum.Touched:Connect(waterPart)

1 Like

Its working on touch certain part but if don’t touch part for while then still issue same error Attempt to connect failed: Passed value is not a function and stop damaging for no reason too.

1 Like

Ok, wait…
I looked at it too quickly

Help me to understand.
Are you wanting the character to continually take damage until either of 2 things happen?

  1. stops taking damage if their health is <= 0
    or
  2. stops taking damage if they are touching the water part

Is that correct?

Yeah, correct. do you need entire code to understand better?

Let me type ups something first (I am loading my studio) and we will see if it helps you to solve your problem.

alr, let me know if you need entire code

Go ahead and post it if you want. Do you just have one water part, or several? How are you finding waterPart?

I do have several waterPart and I do have water script for to make fire disappear(its work so well). by the way, let me show you entire code

local firePart = script.Parent
local canTouch = true
local Debounce = false
local waterPart = game.Workspace:FindFirstChild("waterPart")

local function onTouch(otherPart)
	if Debounce == false then
		Debounce = true

		local hum = otherPart.Parent:FindFirstChild("Humanoid")

		local character = otherPart.Parent

		if hum and canTouch then
			local characterComponents = character:GetChildren()

			for _, part in pairs(characterComponents) do
				if part:IsA("MeshPart") or part:IsA("Part") then
					local fire = Instance.new("Fire")
					fire.Parent = part

					hum:TakeDamage(2)
					wait(0.5)
				end
			end

			repeat
				hum:TakeDamage(2)
				wait(0.5)
			until hum.Health <= 0 or hum.Touched:Connect(waterPart)
			
			wait(1)
		end
		canTouch = true
		Debounce = false
	end
end

firePart.Touched:Connect(onTouch)

1 Like

Ok, so… if the character touches a fire part, the become on fire, and they need to continue to take damage, until they die or touch a water part?

If that is correct, I think you need to have the script be located under the startercharactescripts
and keep the script running but only do damage if player is on fire.

I’ll post an example.

yeah that is correct, thanks for understanding!

FireWaterUnderCharacter.rbxl (58.6 KB)

image

--This is a localscript in StarterCharacterScripts

--Set up or variables
local player = game.Players.LocalPlayer
local character = player.Character
local hrp = character.PrimaryPart
local humanoid = character:WaitForChild("Humanoid")

--Have a variable that keeps track of if we should be taking damage
local damageEnabled = false

--Check if our HumanoidRootPart is being touched.  By doing this (using HumanoidRootPart) it means you
--  need to make sure that your hit box is large enough for the HumanoidRootPart (lets call it hrp) can touch.
--  this also keeps legs and arms from triggering the hit, so if you have an animation that is moving the legs and arms
--  the animation wont accidentally trigger a hit.

hrp.Touched:Connect(function(part)
	--we check the name of the part that hrp hit
	if part.Name == "WaterPart" then
		damageEnabled = false --was a water part so we disable damage
		--remove any fire effects
		if hrp:FindFirstChild("Fire") then
			hrp.Fire:Destroy()
		end
	elseif part.Name == "FirePart" then
		damageEnabled = true --was fire part so we enable damage
		--add fire effects if not already 
		if not hrp:FindFirstChild("Fire") then
			part.Fire:Clone().Parent = hrp
		end
	end
end)



while true do --loop until the character dies
	if damageEnabled == true then --check if we need to take damage
		humanoid:TakeDamage(2) --take the damage
		print("health ",humanoid.Health)
	end
	wait(.5)
end


3 Likes

alr, its work pretty well!!! (if anyone tried do this script is not work then its bc of tall avatar. try adjust scale of part then here you go lol.)

btw thanks!!! for help me lot!

1 Like

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