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

How do I remove my cloned Oxygen value after leaving the ToucherPart Zone?

Working on making an oxygen system for a game. Magnitude works fine for planets, but for ships and shuttles I need to use Zones of some sort for each individual room and hallway. I need to add a method to check if the player is no longer in the ToucherPart to delete the Oxygen Value.

while task.wait(1) do -- Time between damage taken. Change it to whatever you want.
    local results = workspace:GetPartsInPart(ToucherPart)
    local players = {}

    for _, part in pairs(results) do
        local humanoid = part.Parent:FindFirstChild("Humanoid")
        if humanoid and not players[part.Parent] then
            players[part.Parent] = true

            print (part.Name)
            
            local Oxygen = part.Parent:FindFirstChild(SO.Name)
            if not Oxygen then
                print ("Cloning Oxygen To Character")
                SO:Clone().Parent = part.Parent
            end
            
            
        end
    end

end

1 answer

Unsure if the way you designed things will allow for this, but you could try connecting .TouchEnded so that when the player leaves the room they are in, .TouchEnded will fire.

You can read more about .TouchEnded here.

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