Hello, I am trying to make a “smart tweening” ModuleScript to create, play, and destroy tweens automatically as needed. However, while my code works well in a regular Script, it appears that when passing it to a ModuleScript via require()
followed by a function call from the script that required the module, something weird happens when you attempt to pass in a Dictionary. In this context, the Dictionary in question would be the third argument needed by TweenService:Create(), known as “propertyTable”.
Here’s the code in my module:
-- SERVICES
TweenService = game:GetService("TweenService")
-- CLASS
local st = {}
-- AUXILLARY FUNCTIONS
-- Used by all "main functions", which are the functions returned when this ModuleScript is required by another script.
function CreateSmartTween(Target,Info,Properties)
local success,tween = pcall(function()
return TweenService:Create(Target,Info,Properties)
end)
if not success then
warn("SMART TWEEN ERROR! Message: " .. tostring(tween) .. ", trace: \n" .. debug.traceback())
return nil
end
local tConnect = tween.Completed:Connect(function()
tConnect:Disconnect()
tween:Destroy()
end)
return tween
end
function CreateModelTween(Model,Info,CFrameValue)
local success,tween = pcall(function()
return TweenService:Create(Model,Info,{Value = CFrameValue})
end)
if not success then
warn("MODEL TWEEN ERROR! Message: " .. tostring(tween) .. ", trace: \n" .. debug.traceback())
return nil
end
local CFTC = CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
Model:SetPrimaryPartCFrame(CFrameValue.Value)
end)
local tConnect = tween.Completed:Connect(function()
CFTC:Disconnect()
tConnect:Disconnect()
tween:Destroy()
CFrameValue:Destroy()
end)
return tween
end
-- MAIN FUNCTIONS
-- Functions returned by this module when required by another script.
function st:Tween(Target,Info,Properties)
local NewTween = CreateSmartTween(Target,Info,Properties)
if NewTween ~= nil then
NewTween:Play()
end
end
function st:TweenModel(Model,Info,TargetCFrame)
local CFrameValue = Instance.new("CFrameValue")
CFrameValue.Value = Model:GetPrimaryPartCFrame()
local NewTween = CreateModelTween(CFrameValue,Info,TargetCFrame)
if NewTween ~= nil then
NewTween:Play()
end
end
-- return the class
return st
And here’s my LocalScript code:
local ContentProvider = game:GetService("ContentProvider")
repeat wait(1) until ContentProvider.RequestQueueSize <= 0
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SmartTween = require(ReplicatedStorage:WaitForChild("SmartTweenModule"))
local MyPlayer = game.Players.LocalPlayer
local GUI = script.Parent
while MyPlayer.PlayerGui:FindFirstChild("LoadScreen") ~= nil do
wait(1)
end
GUI.Beep:Play()
wait(0.1)
SmartTween.Tween(GUI.Cover,TweenInfo.new(1.5,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out),{BackgroundTransparency = 1}) -- <<<< ERROR OCCURS HERE
GUI.PowerOn:Play()
GUI.Idle:Play()
wait(2)
GUI.Cover.Visible = false
For necessary context, GUI.Cover
is a Frame object parented to a ScreenGui. The module is in ReplicatedStorage so that it can be accessed by both local and server scripts.
When attempting to call the module function from my LocalScript that requested the module previously, the following gets printed to Output:
Does anyone in the developer community have advice for this? Thanks for any help you can provide.
–Catz.
EDIT: Darn typos.