Returning Tween

  1. **What do you want to achieve?

Fix the issue so that I can return the Tween, for the purpose of running code when the tween is completed on the server.

  1. **What is the issue?

The client code does not return the “Tween” variable when be invoked.

  1. **What solutions have you tried so far?

I checked out the related documentation to no result.

-- Server:
local Tween = RenderEvent:InvokeClient(Player, {

								"Tween",
								AttachmentTwo,
								{
									.5,
									Enum.EasingStyle.Quart,
									Enum.EasingDirection.Out,
									0,
									false
								},
								{
									CFrame = AttachmentOne.CFrame * CFrame.new(5,0,0)
								}
							})
--Client
RenderEvent.OnClientInvoke = (function(Data)
	
	local Type = Data[1]
	
	if Type == "Tween" then
		
		local Tween = TweenModule.TweenItems(Data)
		print(Tween)
		return Tween
	end
end)
--Module
local Tween = {}

local TweenService = game:GetService("TweenService")

Tween.TweenItems = function(Data)
	
	local Item = Data[2]
	local Tweeninfo = Data[3]
	local TweenGoal = Data[4]

	local Tweeninfo = TweenInfo.new(Tweeninfo[1], Tweeninfo[2], Tweeninfo[3], Tweeninfo[4])

	local Tween = TweenService:Create(Item, Tweeninfo, TweenGoal)
	Tween:Play()
	
	return Tween
end

return Tween


Im not sure if this might fix it, but your returning the table itself, rename the variable to something else.

1 Like

Unfortunately this still makes it return nil on the server

Using InvokeClient is a bad idea: If the player leaves before they send a response, the server will be left waiting indefinitely. It’s recommeded to use RemoteEvents to send data from the client to the server, to prevent this kind of issue from occurring

Is there a particular reason as to why you’re creating the TweenInfo on the server, sending it to the client, creating the Tween on the client, then sending it back to the server?

2 Likes

Tweens created locally on the Client aren’t able to be sent to the Server because they aren’t replicated.

I suggest using RemoteEvents to notify the Server when a Tween created locally has completed.

1 Like

A. Yeah, I could definitely just use remote events opposed to a remote function. That was a pretty dumb solution I made now that I think about it. lol

B. Running tween on client for performance/smoothness and returning it to server to run code when the tween is completed.

1 Like

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