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

How can I use a spawn function in my module script?

This may be a stupid question, but how would I turn this function into a spawn function:

function ButtonDoorModule.DoorControl(DoorModel)

I tried doing the following:

spawn (function( ButtonDoorModule.DoorControl(DoorModel))

But this didn't work, as I got the following error in the script: Expected ')' to close '(' at column 16), got '.'

local ButtonDoorModule = {}

open = false

  

function ButtonDoorModule.DoorControl(DoorModel)

local TweenService = game:GetService("TweenService")
local Button1 = DoorModel.Button1.Button
local Button2 = DoorModel.Button2.Button
local Door = DoorModel.Door.Main
local tweenInfo1 = TweenInfo.new(2.2,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0)
local tweenInfo2 = TweenInfo.new(0.8,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0)

local Click = Door.Click
local Opening = Door.DoorOpen
local Closing = Door.DoorClose

local DoorOpen = {CFrame = Door.CFrame + Door.CFrame.lookVector * 7.3}
local DoorClose = {CFrame = Door.CFrame}

local Open = TweenService:Create(Door,tweenInfo1,DoorOpen)
local Close = TweenService:Create(Door,tweenInfo2,DoorClose)

  

if open == false and Door.Value.Value == 0 then

Open:Play()

Click:Play()

Opening:Play()

open = true

Door.Value.Value = 1

wait(3)

open = false

Close:Play()

Closing:Play()

wait (1.2)

Door.Value.Value = 0

elseif open == false and Door.Value.Value == 0 then

Click:Play()

Door.Value.Value = 1

wait(4)

Door.Value.Value = 0

wait(1)

end

end

  

return ButtonDoorModule

1 comment

0

Ignore the indentation, it went all weird when I pasted it.

1 answer

✓ Accepted answer

when you do spawn(function() you don't put a name in your example you would not change the module but when you fire the function you would do:

local ButtonDoorModule= require(ButtonDoorModule)

spawn(ButtonDoorModule.DoorControl(DoorModel))

DoorControl is a function so we can put it in a spawn

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