How do I stop a module script

Hi, does anyone know how to stop this module script

local char = game:GetService("Players").LocalPlayer.Character

wait(20)
for i = 100, 0, -1 do
	char.Humanoid.Health = i
	wait(3)
end

because destroying it doesn’t work, I want it if the tool is activated the script needs to stop

Stopped permanently?
If you want it to be stopped permanently you could try something like this:

local char = game:GetService("Players").LocalPlayer.Character
wait(20)
local tool  = ... -- Set this
local ToolActivated = false
tool.Activated:Once(function()
    ToolActivated = true
end)
for i = 100, 0, -1 do
    if ToolActivated then break end
	char.Humanoid.Health = i
	wait(3)
end
1 Like

I did it now there is this infinite yield, do you know how to fix this yield:

local tool  = game.Players.LocalPlayer:WaitForChild("Backpack"):WaitForChild("Pillbottle")

the player needs to pick the item up
this was my problem before

Is it the only item that the player can pick up?

no, there are 3 tools in the game

IG this implementation will have to do then:

local char = game:GetService("Players").LocalPlayer.Character
local ToolActivated = false
char.ChildAdded:Connect(function(child)
    if child.Name == "Pillbottle" and child:IsA("Tool") then
        child.Activated:Once(function()
            ToolActivated = true
        end)
    end
end

for i = 100, 0, -1 do
    if ToolActivated then break end
	char.Humanoid.Health = i
	wait(3)
end
1 Like

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