So, I’m trying to pass TweenInfo from Server to Client.
Here is my server code:
function Area:ShowDescription(player: Player)
local tInfo = TweenInfo.new(3, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, true);
print("On the server, tInfo is:\n" .. tInfo);
ReplicatedStorage.Events.ShowAreaDescription:FireClient(player, self.Name, self.Description, tInfo);
end
and here is my client code:
local function showDescription(name, description, tInfo)
--print(name, description, tInfo);
print("On the client, tweenInfo is:\n" .. tInfo);
end
game:GetService("ReplicatedStorage").Events.ShowAreaDescription.OnClientEvent:Connect(showDescription);
The other parameters, name and description, are passed through. It’s just tInfo that’s not passing through.
At first, I figured that TweenInfo is something you can’t pass through a RemoteEvent. I know there are certain types of information that get lost in the firing of a RemoteEvent… but I looked up my problem, and there’s one topic that addresses the problem I have. It says you can pass TweenInfo…
What is the post that says you can pass TweenInfo? maybe is on a different context.
I think its because you are creating the TweenInfo as an Instance of the ServerScript, so you cant pass that instance directly to client. Instead you could pass the values/properties of the TweenInfo as a table/string, and rebuild the TweenInfo on client side.
This is because you cannot pass non-replicated instances to the client. TweenInfo is considered non-replicated instance, as client is clueless whenever it exists or not, so it ends up nil in server/client. You can find this limitation here.
If you really need to pass tween information, you have to convert that into table first, and then pass it to the servers/clients and then use that table to construct a tween info. Here’s the script that would look like as result
type TableTweenInfo = {
Time: number,
EasingStyle: Enum.EasingStyle,
EasingDirection: Enum.EasingDirection,
RepeatCount: number,
Reverses: boolean,
DelayTime: number
} --this is not mandatory, but I added typechecking just for convinience sake.
local function TweenInfoToTable(tweenInfo: TweenInfo): TableTweenInfo
return {
Time = tweenInfo.Time,
EasingStyle = tweenInfo.EasingStyle,
EasingDirection = tweenInfo.EasingDirection,
RepeatCount = tweenInfo.RepeatCount,
Reverses = tweenInfo.Reverses,
DelayTime = tweenInfo.DelayTime
}
end
If you don’t need this typechecking stuff, here’s without one:
local function TweenInfoToTable(tweenInfo)
return {
Time = tweenInfo.Time,
EasingStyle = tweenInfo.EasingStyle,
EasingDirection = tweenInfo.EasingDirection,
RepeatCount = tweenInfo.RepeatCount,
Reverses = tweenInfo.Reverses,
DelayTime = tweenInfo.DelayTime
}
end
I’m bumping this since it has no solution and I had to do a google search to find what was happening with my code as well. I figured since this topic came up in my google search that I would post a better solution that I came up with for others to use.
I’m guessing since Roblox did not replicate this through remotes that they did not intend for this to be done. So avoiding sending tweenInfos is likely recommended.
-- on server:
local function PackTweenInfo(TI : TweenInfo) : table
return {
TI.Time,
TI.EasingStyle,
TI.EasingDirection,
TI.RepeatCount,
TI.Reverses,
TI.DelayTime,
}
end
-- somewhere:
RE:FireClient(somePlayer, PackTweenInfo(myTweenInfo))
-- on client:
RE.OnClientEvent:Connect(function(TI)
TI = TweenInfo.new(table.unpack(TI))
-- use tweeninfo TI
end)