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

Passing a sound from a localscript to a module script?

Asked by
hokyboy 270 Moderation Voter
3 years ago

The localscript

local Currsound = script.Parent[v.Name]
MusicModule.Fadeout(Currsound)
Currsound:Stop()
wait(1)
script.Parent.Sea:Play()

The module

local MusicModule = {}

function Fadeout(Currsound)
    for count = 1,5 do
        Currsound.Volume = Currsound.Volume - 0.1
    end 
end

return MusicModule

I wanted a module so i can fade music with just 1 line of code My error is Players.Sofian9600.PlayerGui.REGIONSMUSIC.RegionalMusic:26: attempt to call a nil value

1 answer

Log in to vote
1
Answered by 3 years ago

Module script:

local MusicModule = {}

    MusicModule.Fadeout = function(sound)
        for count = 1,5 do
            sound.Volume = sound.Volume - 0.1
        end
    end

return MusicModule

Local script:

local Currsound = script.Parent[v.Name] 
local moduleScript = yourmodulescript -- Write there modulescript location
moduleScript.Fadeout(Currsound)  -- call the function inside the modulescript
wait(1.6) -- wait for fadeout to finish
Currsound:Stop() 
wait(1)
script.Parent.Sea:Play()
Ad

Answer this question