Door won't open before module script function is done

Hello.

My door won’t tween before my module script function is done, i have tried multiple fixes but it just won’t work, and i have searched on the forum and youtube and can’t find a solution

Thanks.

here is my script that opens my door:

local TS = game:GetService("TweenService")
local door = script.Parent.Primary
local hitbox = script.Parent.Primary.Hitbox
local sound = script.Parent.Light.Hit
local opensound = script.Parent.Primary.Door.OpenSound
local endpos = door.Endpos

door.CFrame = door.CFrame * CFrame.Angles(0,0,0)

hitbox.Touched:Connect(function()
	door.Hitbox:Destroy()
	local RoomGeneration = require(game.ReplicatedStorage.RoomGeneration)

	RoomGeneration.GenerateRoom()
	
	TS:Create(door,TweenInfo.new(0.6),{CFrame = endpos.CFrame}):Play()
	script.Parent.Light.Attachment.PointLight.Enabled = true
	script.Parent.Light.Fade.Transparency = 0.2
	script.Parent.Light.Material = "Neon"
	script.Parent.Light.Fade.Transparency = 0
	opensound.Playing = true
	wait(0.1)
	opensound.Playing = false
	sound:Play()
	script:Destroy()
end)

Try using coroutine.wrap with the GenerateRoom function

coroutine.wrap(RoomGeneration.GenerateRoom)()
1 Like

still dosen’t work for some reason