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

Passing a sound from a localscript to a module script?

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

✓ Accepted answer

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()

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