Having issue with the player skipping obby stages, then script not working

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

  1. What do you want to achieve? Keep it simple and clear!
    I want the script to run for every single part, no matter if for example, player is at stage 2, then goes to stage 5, it doesn’t work. The script seems to only work in a chronological order

  2. What is the issue? Include screenshots / videos if possible!
    The issue is that whenever a player goes from stage 2 to 6, or 7, basically not chronologically, the script just doesnt run

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried tables, didn’t work

Also, if you could, I am a new developer, I’ve messaged the entire script, but what are some coding practices you would recommend to do?

-- Get the StageSpawns folder from the workspace
local spawns = workspace:WaitForChild("StageSpawns")
-- Table to keep track of players who have touched the parts
local touchedPlayers = {}

-- Function to handle the touch event on the part
local function onPartTouch(part, touchedPart)
    -- Check if the touched part's parent has a Humanoid (to verify it's a character)
    local humanoid = touchedPart.Parent:FindFirstChild("Humanoid")
    if not humanoid then return end

    -- Get the StageHolder from the part
    local stageHolder = part:FindFirstChild("StageHolder")
    if not stageHolder then
        warn("StageHolder not found")
        return
    end

    -- Get the Confetti particle effect and sound
    local particle = script:WaitForChild("Confetti")
    local sound = workspace.SoundGame.ObbyWin
    local soundClone = sound:Clone()
    local particleClone = particle:Clone()

    -- Change the BrickColor of the StageHolder and the part
    stageHolder.BrickColor = BrickColor.new("Lime green")
    part.BrickColor = BrickColor.new("Dark green")

    -- Create an invisible part above the stageHolder to hold the particle effect
    local invisiblePart = Instance.new("Part")
    invisiblePart.Size = Vector3.new(13.095, 2, 7.076)
    invisiblePart.Anchored = true
    invisiblePart.CanCollide = false
    invisiblePart.Position = stageHolder.Position + Vector3.new(0, 7, 0)
    invisiblePart.Transparency = 1
    invisiblePart.Parent = stageHolder

    -- Enable the particle effect on the invisible part
    particleClone.Parent = invisiblePart
    particleClone.Enabled = true

    -- Get the Head part of the character who touched the part
    local head = touchedPart.Parent:FindFirstChild("Head")
    if not head then
        warn("Head not found")
        return
    end

    -- Play the sound on the character's head
    soundClone.Parent = head
    soundClone:Play()
    soundClone.Ended:Wait()
    soundClone:Destroy()

    -- Wait for 1.5 seconds before destroying the invisible part and disabling the particle effect
    task.wait(1.5)
    invisiblePart:Destroy()
    particleClone.Enabled = false
end

-- Connect the touch event for each part in the StageSpawns folder
for _, part in pairs(spawns:GetChildren()) do
    if part:IsA("BasePart") then
        part.Touched:Connect(function(hit)
            local humanoid = hit.Parent:FindFirstChild("Humanoid")
            if humanoid then
                local player = game.Players:GetPlayerFromCharacter(hit.Parent)
                if player and not touchedPlayers[part] then
                    -- Mark the part as touched and prevent multiple triggers
                    touchedPlayers[part] = true
                    part:SetAttribute("Touched", true)
                    task.delay(1, function()
                        part:SetAttribute("Touched", false)
                        touchedPlayers[part] = nil
                    end)
                    onPartTouch(part, hit)
                end
            end
        end)
    end
end

Screenshot 2024-06-04 000029
Also, this is a local script in the starterpack, the confetti is parented to it

is your game using streaming-enabled by any chance? (check under workspace properties)

if it is, test it again with it turned off

2 Likes

Wow it did work, thank you
Also what’s streaming enabled? Never heard of it, and why did it make my specific script work?

StreamingEnabled is a feature that streams out parts that are far away from the player. Think of how in Minecraft blocks that are far away disappear. This is used to improve the performance of games that have a lot of parts. It fixed your code because the local script was not able to see spawns that are too far away.

1 Like

it’s a feature that used to be opt-in (but is now the default on new experiences), that unloads parts and models that are far away on the client.

(meanwhile games that have it off load all the instances into memory, regardless of graphic settings and draw distance)

I really dislike it being default, because if I was learning how to script from scratch again it would be really confusing.
Developing for streaming-enabled is generally more complicated and usually requires more advanced knowledge

1 Like