How to call a function in module script in client

Hello Developer! I am having troubling calling a function I created from a module script to client. I did this because I had someone told me to do something like this to organize the script more. So I was wondering why it wouldn’t work.

Here is the module:

local module = {}

--Prompt
local prompt = workspace.XmasEvent:WaitForChild("EventSnowglobe"):WaitForChild("Glass"):WaitForChild("Attachment"):WaitForChild("ProximityPrompt")

--Parts
local model = workspace.XmasEvent:WaitForChild("EventSnowglobe")
local Glass = model:WaitForChild("Glass")
local NeonGlass = model:WaitForChild("GlassNeon")


--Functions

local function GlassDisappear()
	
	local TweenService = game:GetService("TweenService")

	local tweenInfo = TweenInfo.new(
		1, -- Time
		Enum.EasingStyle.Linear, -- EasingStyle
		Enum.EasingDirection.Out -- EasingDirection
	)
	
	local tweenInfoNeonFade = TweenInfo.new(
		2, -- Time
		Enum.EasingStyle.Quint, -- EasingStyle
		Enum.EasingDirection.Out -- EasingDirection
	)

	local GlassTween = TweenService:Create(Glass, tweenInfo, { Transparency = 1 })
	
	local NeonTweenAppear = TweenService:Create(NeonGlass, tweenInfo, { Transparency = 0 })
	
	local NeonTweenDisppear = TweenService:Create(NeonGlass, tweenInfoNeonFade, { Transparency = 1 })
	
	task.wait()
	GlassTween:Play()
	NeonTweenAppear:Play()
	NeonTweenAppear.Completed:Wait()
	wait(1)
	NeonTweenDisppear:Play()

end

return module

Here is the client after the remote event:

local FunctionModule = unpack(require(game.ReplicatedStorage:WaitForChild("CutsceneFunctionsEffect")))

Event.OnClientEvent:Connect(function(player)
--	prompt.Enabled = false
	--task.wait()
	--Cutscene1:Play()
--	Cutscene1.PreviousCameraType = Enum.CameraType.Scriptable
	FunctionModule.GlassDisappear()
	--task.wait()
	--camShake:StartShake(4, 3 , 1, 2, 3, 6)
--wait(9)
	--camShake:Stop()
end)

(Please ignore the other stuff)

Thanks for the help.

change your local function line in the module to this:

function module.GlassDisappear()
--code
end
1 Like

Here is an example of a module:


-- Tables store multiple values in one variable
local MyFunctions = {}

-- Add a few functions to the table
function MyFunctions.foo()
	print("Foo!")
end

function MyFunctions.bar()
	print("Bar!")
end

-- ModuleScripts must return exactly one value
return MyFunctions

Thank you! Although I tried that and I got this instead:

image

Did you return the table of functions in the module? Also, don’t unpack the module.

Yes, here is the new module:

could it possibly be how I called the module in the local script?

local EventCutsceneFunctions = {}

--Prompt
local prompt = workspace.XmasEvent:WaitForChild("EventSnowglobe"):WaitForChild("Glass"):WaitForChild("Attachment"):WaitForChild("ProximityPrompt")

--Parts
local model = workspace.XmasEvent:WaitForChild("EventSnowglobe")
local Glass = model:WaitForChild("Glass")
local NeonGlass = model:WaitForChild("GlassNeon")


--Functions

function EventCutsceneFunctions.GlassDisappear()
	
	local TweenService = game:GetService("TweenService")

	local tweenInfo = TweenInfo.new(
		1, -- Time
		Enum.EasingStyle.Linear, -- EasingStyle
		Enum.EasingDirection.Out -- EasingDirection
	)
	
	local tweenInfoNeonFade = TweenInfo.new(
		2, -- Time
		Enum.EasingStyle.Quint, -- EasingStyle
		Enum.EasingDirection.Out -- EasingDirection
	)

	local GlassTween = TweenService:Create(Glass, tweenInfo, { Transparency = 1 })
	
	local NeonTweenAppear = TweenService:Create(NeonGlass, tweenInfo, { Transparency = 0 })
	
	local NeonTweenDisppear = TweenService:Create(NeonGlass, tweenInfoNeonFade, { Transparency = 1 })
	
	task.wait()
	GlassTween:Play()
	NeonTweenAppear:Play()
	NeonTweenAppear.Completed:Wait()
	wait(1)
	NeonTweenDisppear:Play()

end

return EventCutsceneFunctions

I don’t know why I didn’t see the don’t unpack the module but I delete the unpack line and it worked, thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.