Scripting Helpers is winding down operations and is now read-only. More info→
Log in to vote

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

Asked by 1 year ago

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



1 answer

Log in to vote
Answered by
0x5y 105
1 year ago

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.


Answer this question