--[[
	Tween Event handler
	Phoenix
]]


local Sender    	 = game:GetService("ReplicatedStorage").Game.Events.Game.Tween
local ServerListener = game:GetService("ServerScriptService").Server.Events.Tween

local CatchUpData = {} -- Instance = {InstanceTweened = Instance, Frame = CFrame}

ServerListener.Event:Connect(function(InstanceToTween, ToCFrame, Time, Data)
	local Ins
	
	if InstanceToTween ~= nil then
		if InstanceToTween:IsA("Model") then
			if InstanceToTween.PrimaryPart then
				Ins = InstanceToTween.PrimaryPart
			end
		else
			Ins = InstanceToTween
		end

		local Players = game:GetService("Players"):GetChildren()

		for I = 1, #Players do
			local Player = Players[I]

			Sender:FireClient(Player, InstanceToTween, ToCFrame, Time, Data)
		end

		wait(Time)

		if InstanceToTween.PrimaryPart then
			InstanceToTween:SetPrimaryPartCFrame(ToCFrame)
		elseif InstanceToTween:IsA("BasePart") then
			InstanceToTween.CFrame = ToCFrame
		else
			print("Attempted to tween a non model Instance: ".. InstanceToTween:GetFullName())
		end
	end	
end)
