You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
I want loop stop on certain touch part or loop will stop on health 0
What is the issue?
wont stop loop on (and). if I use or then stop for no reason.
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.)
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.
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)
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.
--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