Best way to replicate tweens played in one client to other clients

I’ve been scavenging the dev forum but can’t find the answer.

What I can think of is creating a remote event that allows the client to send any tween to be played on the server, but this brings some serious security issues.

So, what’s the best method? The above but with sanity checks? An unreliable remote event (idk)?

1 Like

Regardless of what method you use, communication between clients requires some kind of server involvement to send data to and fro.

With this in mind, best practice would likely be for the server to tell the clients when a tween should occur. However, if it must be initiated from a client, serious sanity checks would be needed, such as having a pre-defined list of valid tweens so that one client cannot tell others to do something arbitrarily.

One alternative could be for the client to inform the server that a particular event has happened, the server then does its necessary checks, then relays that message to the other clients. Whereby they then perform the corresponding tween, rather than sending the tween instructions.

Best of luck!

1 Like

I was mainly confused about what kind of sanity check to make, this fits nicely, thank you!

For anyone trying to do the same in the future

Another issue I faced was the client that played the tween having the server tween replicated back, causing the property to act weird, but I managed to fix it with this local script:

local tweenService = game:GetService("TweenService")
local replicatedStorage = game:GetService("ReplicatedStorage")

local replicateServerTween = replicatedStorage.remoteEvents.replicateServerTween

replicateServerTween.OnClientEvent:Connect(function(instance, tweenInfoTable, propertyTable)	
	tweenService:Create(
		instance,
		TweenInfo.new(table.unpack(tweenInfoTable)),
		propertyTable
	):Play()
end)

Then on the server:

local replicateServerTween = replicatedStorage.remoteEvents.replicateServerTween

local function fireAllClientsExcept(remoteEvent, data, exception)
	for _, player in players:GetPlayers() do
		if player ~= exception then
			remoteEvent:FireClient(player, table.unpack(data))
		end
	end
end

local validTweensData = {
	x = {{.25}, {Color = Color3.fromRGB(0, 0, 255)}},
	y = {{.4}, {Color = Color3.fromRGB(255, 0, 0}}
}

replicateTween.OnServerEvent:Connect(function(player, instance, tweenType)
	fireAllClientsExcept(
		replicateServerTween,
		{instance, table.unpack(validTweensData[tweenType])},
		player
	)
end)

Then just call fireServer on the “replicateTween” remote event from any client wit a tween type and it will replicate to all other clients.

Of course, the client can ask for any of the “valid” tween whenever since there are no sanity checks for this, you might want to adapt that.

I’m not worried since the tweens I’m replicating like that are purely visuals, colors, etc., and in my project, it’s nothing that provides any advantage/breaks something if exploited. (that’s also why I didn’t want to do it on the server, delays in visual effects are terrible)

Again, thank you @JayzYeah32, you’re very kind!

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