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

I'm confused with my script, what did I do that messed it up?

Asked by 5 years ago
Edited 5 years ago

I made a script so when the player enters a certain part of the game the player walks slower and music plays, and when he's out everything stops. Everything works but the music fading in and out. Here's the script. The music part messed up the whole script, so where did I go wrong?

local scene = script.Parent
local function steppedOn(part)  
local parent = part.Parent  
if game.Players:GetPlayerFromCharacter(parent) then     
parent.Humanoid.WalkSpeed = 2.5
        wait(0.5)
        local S1 = Instance.new ("Sound",workspace)
        if S1 == true then 
            local S1 = Instance.new ("Sound",workspace)== false
        end
        S1.SoundId = "rbxassetid://380808812"
        S1.Volume = 0
        S1:Play()
        for i = 1,50 do
            wait(0.1)
            S1.Volume = S1.Volume + 0.05
        end
        repeat wait() until S1.TimeLength > 20

        wait(20)
        for i = 1,50 do
            wait(0.1)
            S1.Volume = S1.Volume - 0.05
            end
        script.Parent:Destroy()

        parent.Humanoid.WalkSpeed = 16

scene.Touched:connect(steppedOn)

    end
end


0
Try adding i = i + 1 after you set the volume TiredMelon 405 — 5y
0
for loops iterate by 1 by default Gey4Jesus69 2705 — 5y
0
ewww :connect(), use :Connect() LoganboyInCO 150 — 5y
View all comments (2 more)
0
If scene is script.Parent, and script.Parent has just been destroyed, it doesn't seem good to scene.Touched:Connect(). aschepler 135 — 5y
0
You made another thread about this? TheOnlySmarts 233 — 5y

Answer this question